jQuery .load() call doesn't execute javascript in loaded html file
Posted
by Mike
on Stack Overflow
See other posts from Stack Overflow
or by Mike
Published on 2009-05-20T20:07:50Z
Indexed on
2010/04/07
6:03 UTC
Read the original article
Hit count: 165
This seems to be a problem related to Safari only. I've tried 4 on mac and 3 on windows and am still having no luck.
What I'm trying to do is load an external html file and have the Javascript that is embedded execute.
The code I'm trying to use is this:
$("#myBtn").click(function() {
$("#myDiv").load("trackingCode.html");
});
trackingCode.html looks like this (simple now, but will expand once/if I get this working):
<html>
<head>
<title>Tracking HTML File</title>
<script language="javascript" type="text/javascript">
alert("outside the jQuery ready");
$(function() {
alert("inside the jQuery ready");
});
</script>
</head>
<body>
</body>
</html>
I'm seeing both alert messages in IE (6 & 7) and Firefox (2 & 3). However, I am not able to see the messages in Safari (the last browser that I need to be concerned with - project requirements - please no flame wars).
Any thoughts on why Safari is ignoring the Javascript in the trackingCode.html file?
Eventually I'd like to be able to pass Javascript objects to this trackingCode.html file to be used within the jQuery ready call, but I'd like to make sure this is possible in all browsers before I go down that road.
Thanks for your help!
© Stack Overflow or respective owner