Hi,
I have a page, which uses the code below to load in HTML from an external file upon a URL being clicked (I have included unique onclick="" code for each URL in the index.html as desired). The dynamic loading works fine... I have tried including my code from the proposed event handler, just after the load as below, but that does not work.
At the moment, I am calling the event handler code as a function at the very bottom of the secondary page(s) so that after it has loaded, it then 'refreshes' the Javascript code as needed. This works as is. I just want to make it more modular by including all Javascript centrally, without the need to add stuff to every page I want to add, dynamically. It would be great to set up some sort of event handler for changes made to the contents of '#dynamic'.
Or i guess another way, would be to set up all of the javascript in index.html (through a Javascript include) that remains global, even when new content is added to a page/view. Is that possible?
- function SomeURLHasBeenClicked(){
- $('#dynamic').load('somepage.html');
- //tried including it here, no luck!
- event.preventDefault();
- }
Any help, is much appreciated and sorry if my questions are n00bish.
GG
*** UPDATE ***
Well, that was easy. Seems I figured it out myself, right after I made this post. Delayed lateral thinking, huh?
Anyway, I shall leave it here with my solution in case anyone needs it. It might not be the best or most elegant solution, but it allows me to have all my code in once place, which makes me all warm and fuzzy inside.
Solution
- function SomeURLHasBeenClicked(){
- $('#dynamic').load('somepage.html', function() {
- RunMyScriptRefreshFunction();
- });
- event.preventDefault();
- }