0

At the moment I have a HTML where files can be dynamically loaded.

I am using the load() function. Within the loaded HTML file, there is an external script that I would like to execute, but it won't execute? The script will execute if I go to the HTML document directy, but not when I am using the load function.

Here is my code:

Index Page

$(".pages").load("page1.html");

page1.html

<script type="text/javascript" src="alert.js"></script>
<h1>Welcome to page one</h1>

Alert.js

alert("This page has loaded");

I can confirm the rest of page1.html appears, just the javascript file won't

Help will be appreciated guys!

Thanks Peter

Peter Stuart
  • 2,362
  • 7
  • 42
  • 73
  • Can you confirm `page1.html` is loading `alert.js` correctly? Check the Network console in your browser to make sure it's coming back with a status 200. Well, make sure it isn't a 4xx or 5xx code. – Gromer Oct 02 '12 at 23:12
  • Look that http://stackoverflow.com/questions/889967/jquery-load-call-doesnt-execute-javascript-in-loaded-html-file – Mate Oct 02 '12 at 23:14
  • It is loading correctly if I went to mysite.com/page1.html. It doesn't load it when I use the load() function with jQuery. – Peter Stuart Oct 02 '12 at 23:14
  • @Mate the reason why his script wasn't working was because he has the head tags in his external html doc, I don't – Peter Stuart Oct 02 '12 at 23:16
  • Do you see any errors in your console? It might be a path issue, path to the JS file should be valid from the containing page – Hazem Salama Oct 02 '12 at 23:19
  • Mope, my console is clean before and after loading the file. All files share the one directory so it can't be a path issue – Peter Stuart Oct 02 '12 at 23:20

0 Answers0