Howto know when the DOM is loaded and ready

2 posts, 0 answers
  1. Pascal
    Pascal avatar
    3 posts
    Member since:
    Nov 2010

    Posted 30 Nov 2011 Link to this post

    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);
       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

  2. Kiril Stanoev
    Kiril Stanoev avatar
    1512 posts

    Posted 02 Dec 2011 Link to this post

    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 >>

Back to Top