script tag not activating

Started by tjs7664, May 22, 2012, 12:52:20 AM

tjs7664

In the header of my site, i have jquery loading in an html file into a div.
Inside the div is 2 external script files, neither of which ever loads (I have onload="alert('-');" in them, which never activates), but it goes into the script file below. if I hardcode it, it works fine.

The closest I got it to working was removing
$(document).ready(function() {});
(so I could get the href), and then putting

<body>
<div id="curId"> <script> $("#curId").load(href + "loadedFile.html"); </script> </div>
</body>

However, that still didn't active the script files, but rather triggered one of my attempted work arounds.

I sort of understand why it doesn't work, but I'm not exactly sure.
My guess is since I'm still inside a script tag when I load it in, the script tags in the loaded file are never triggered even though the web page accepts them as script tags, and does not show it as text. However, even if I'm right, I can not think of a way to have the loaded script work.

Any help/advice is appreciated, and some code posted below.


Main file I'm loading a file into:

<!DOCTYPE HTML>
<html>
<head>
<title>Thin-Crust Pizza</title>
<link rel="icon" href="../../favicon.ico" />
<meta charset="utf-8" />

<script src="pizza.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <!--Code here is so that load work properly in firefox when going up a directory (works fine though messy)-->
<script> $(document).ready(function() { var href = window.location.href.split("/");
href = window.location.href.replace(href[href.length-2] + "/" + href[href.length-1],"");
$("#curId").load(href + "loadedFile.html"); }); </script>
</head>

<body>
<div id="curId"> <script> alert("in");</script> </div>
</body>
</html>


Loaded in file (or at least the problem area)

<!-- Webs.com Freebar -->
<div id="freeBar" style="float:right;">
<script onload="alert('-');" language="JavaScript" src="http://images.freewebs.com/JS/Freebar/btn_mirrorgrey.js"></script>
<script onload="alert('-');" type="text/javascript" src="http://images.freewebs.com/JS/Freebar/freebar.js"></script>
<script>
// Some solution ideas tried here
alert("1");
$.getScript('http://images.freewebs.com/JS/Freebar/btn_mirrorgrey.js');
$.getScript('http://images.freewebs.com/JS/Freebar/freebar.js');

function loadjscssfile(filename){
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
}
loadjscssfile("http://images.freewebs.com/JS/Freebar/btn_mirrorgrey.js");
loadjscssfile("http://images.freewebs.com/JS/Freebar/freebar.js");
alert("2");
</script>
</div>