On index.html ; an action of the user would trigger a .load() event that load a document generated by php on a div. The loaded document would includes some javascript code. I would want to call the javascript function that is originally defined on index.html. How can it be done? Simply calling the function on the loaded document wouldn't work.
2 Answers
call the function you want in the callback argument of the load function
content.load("../includes/fetch.php",{
'data':url
},function(){
whatever_function();
}
);
Comments
You want all the javascript on the index page, using .on()--which deals with present and future. Meaning you can load something into a div and have it still work. If you try to have the relevant javascript on the dynamically loaded php it won't work.
10 Comments
charlietfl
this is making a big assumption that the function has anything to do with events
charlietfl
-1 last statement about calling code from remote page is simply not true
charlietfl
wow... just pointing out answer is invalid... don't take it so seriously. If you post false information here...expect it to be rebutted as it serves little value
charlietfl
it is still false. Why you insist on dragging this out is beyond me. Your attention could be put to better use clarfiying answer with true statements
charlietfl
grow up and use this site properly
|
<div>, but want to call the function defined at window scope?