Custom BES Web Report DOM model

I have authored several custom Console Dashboards that give different functionality based on user input, using JavaScript. Simple things like checkboxes, textbox search fields, etc.

I’m trying to port some of these to BES Web Reports to give some search functions to non-console operators. I’m having some difficulty with the DOM though. If I include any script for the document.onLoad() event it does not fire and no further script code will execute. If I remove the document.onLoad(), I cannot access any properties through the document object - no document.getElementById() calls work, for example.

Can anyone give tips on retrieving document properties via script in BES Web Reports?

1 Like

I wonder if just putting the scripts at the end of the document would help at all, if not doing that already?

Are you using jQuery?

Can you post some of the code?

I had it as simple as

<script>
document.onLoad() {
alert('Hello world');
}
</script>

What I suspect is that internally our custom web report may be in some kind of <eval> or ‘include’ block of the main page, and is somehow not included as part of the top-level document object. Maybe I’m totally off my rocker on that one though.

What I haven’t been able to find are any references as to what should work in a BES web report.

I’ve made some progress to share. Here are a couple of things I’ve found. Given the various function definitions below, the remaining part of the function executes or does not execute as the comments describe

> // document.onload does not work at all
> //document.onload=function(){

> // Defining window.onload in this way works in a Console Dashboard but not in a BES Web Report
> //function window.onload() {
    
> //  Defining the function in this way as part of either this.onload or as window.onload does work in BES Web Reports.  Still need to check it in a Console Dashboard.
> //this.onload=function(){
> //window.onload=function(){

> alert('Hello from onload');
> alert(Object.keys(this).join('\n'));
> };

I need to get the functionality of onload() working because as part of my “real” onload I will be populating a Relevance query based on the content of a textarea (which has a default value), but the given textarea element may not exist until the document has finished loading. So I believe the best way to handle that is through the onload() event.

And now I can’t find a reference to actually using document.onLoad() in my Dashboards, I was actually using window.onload().

1 Like

One more update. I’ve found the following format to work correctly in both BES Web Reports and as a Console Dashboard:

this.onload=function() {
	UpdateRelevance();
}

In my case the UpdateRelevance() function is updating a text area based on some user selections or to a default value when the window is loading.

I found another quirk in how the Console (or likely Internet Explorer, as the Console renders in IE) versus Web Reports (which I browsed with Chrome).

Given the following HTML element

<input type="checkbox" name="chkNegativeResult"> Show computers with no matching results <br>

When I tried to retrieve the value via the JavaScript

document.getElementById('chkNegativeResult').checked

it would die on BES Web Reports rendered in Chrome but would work correctly in the Console. I suspect that the proper thing is to die there (the checkbox does have a ‘name’ but not an ‘id’), but IE seems to be forgiving in that case. It works properly in both environments when I change the checkbox ‘name’ to an ‘id’.

It seems like you could run the function when the body loads.

<body onload="myFunction()">
    <p>Hello World</p>
</body>

Otherwise, I think this.onload=function() makes the most sense, but I’m unsure of if it is a recommended use.


Related:

http://www.w3schools.com/jsref/event_onload.asp