This is a migrated thread and some comments may be shown as answers.

Howto know when the DOM is loaded and ready

1 Answer 35 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Pascal
Top achievements
Rank 1
Pascal asked on 30 Nov 2011, 10:04 AM
Hi all,
I load a html site into the radhtmlplaceholder which contains JS Function that I have to call to initialize the Html page. How do i know when the js functions are completely loaded and ready for use?

When i call them to early, the browser raises an exception which gets shown to the user and that is not really nice.

I call the JS in my Loaded Html page with the following method

var serializedContext = JsonConvert.SerializeObject(dtoPoolPartyContext);
string code = String.Format("document.getElementById('myIFrame').contentWindow.App.setContext({0});", serializedContext);
try
{
   var output = HtmlPage.Window.Eval(code);
}

Does someone have a suggestion how to achieve that?

I think of the following workarounds,
-Poll the site for a special tag in the dom, so then i know when it's ready
-Set the frontend to a defined sleeptime (5 seconds or so)  which is really ugly


Cheers
Pascal

1 Answer, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 02 Dec 2011, 12:50 PM
Hello Pascal,

 One workaround I can come up with is to listen for the onload event of the HTML page and from the event handler of the onload event to call your Silverlight method.

Bellow are some links you might consider useful:

HTML Bridge: Interaction Between HTML and Managed Code

Walkthrough: Calling JavaScript from Managed Code

Walkthrough: Calling Managed Code from JavaScript

Calling Javascript functions from RadHtmlPlaceholder

All the best,
Kiril Stanoev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
HTMLPlaceHolder
Asked by
Pascal
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question
or