Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a div onload function?

Tags:

javascript

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

like image 898
Jenny Avatar asked Dec 14 '11 06:12

Jenny


2 Answers

Have you used jQuery before? If so, just get the id of your div (let's say "SomeDiv") and then use the "ready" method like this:

$("#SomeDiv").ready(
function(){
     //do stuff
    });
like image 58
Matt Cashatt Avatar answered Oct 17 '22 18:10

Matt Cashatt


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.

like image 29
Jason Avatar answered Oct 17 '22 19:10

Jason