I’m new to jQuery. I’m trying to get familiar with it so I’m creating a webpage that I can input my filepath or URL and it loads my webpage then inserts the jquery file to the head section. When I open my HTML file in my browser it starts displaying my script after I initialize a variable with a string. See code:
Script:
var $txt = "<script></script>";
var $webpage = null;//webpage object
$(document).ready(function(){
$("#sub").click(function(){
var $filepath = $("#filep").val();
$webpage.load($filepath, null, function(){alert('Load was performed.');}).$("head").append($txt);
$("script:last").attr("id","JQfile");
$("#JQfile").attr("type","text/javascript");
$("#JQfile").attr("src","jquery-1.6.1.js");
});
});
HTML:
<head><script src="jquery-1.6.1.js"></script></head>
<body>
<div id="main">
<form>
URL/FilePath: <input id="fname" type="text" name="file"/>
<br/>
<input id="sub" type="submit" value="Submit"/>
</form>
</div>
</body>
I’m sure this is some stupid syntax error but I need another set of eyes to locate it.
The
</script>in your string closes the<script>tag early.To prevent that, change it to
</" + "script>".