Calling Onload From A Page Inside Object Element RRS feed

  • Question

  • User1928065626 posted

    My index.html page has an Object tag and it is used to display different pages when different buttons are clicked. I would like to call the Onload() function and execute some functions within it when a page loads inside of the Object tag.

    Since the index page also calls the Onload() function, I am unsure where to place the functions that is used by the page inside the Object tag. I have a couple questions on what might happen if I put the the functions used by the index page and the page in the Object tag in the same Javascript file.

    1 - When a page inside the Object tag loads, will the Onload() function even execute?

    2 - If I only want functions that are used by the index page to be executed when it loads and only functions that are used by the page in the Object tag to be executed when it loads, should I put them in two separate Onload() functions in two separate Javascript files? Can a web site have more than one Onload() function?

    Monday, April 30, 2018 3:31 AM

All replies

  • User753101303 posted


    onload applies to particular tags. So use body onload for what you want to be done when the page is loaded and according to http://www.w3.org/TR/html5/embedded-content-0.html#the-object-element point 6, you have as well an onload event for the object tag.

    It may give something such as :

    <!DOCTYPE html>
    <body onload="alert('body');">
    <object data="https://www.bing.com/" onload="alert('object');" id="o">
    <input type="button" onclick="document.getElementById('o').data='https://www.google.com/';">

    It should show "object", "body" first. If you click the button it will show "object" again (though www.google.com won't be shown as it sends a header to prevent being shown inside another document).

    Monday, April 30, 2018 10:47 AM