Jenny Jenny - 6 months ago 64
Javascript Question

How to make a div onload function?

I want to load an HTML page as a div inside my webpage by removing its HTML and body tags. But the HTML page has a

<body onload=" ... " >
, I need this function to continue working. Seems
<div onload=" ... " >
is not working. How can I insert this onload function into my website's body (on this page only) without directly editing my original website code (php)?

Answer

you can use jQuery.load to load the contents of the page into your div

$(document).ready(function() {
  $("#containing-div").load("[url of page with onload function]");
});

the code above goes in the page that contains the div. the page with the onload function doesn't get changed.

Comments