Want to set 'src' of script to my IP-Won't load in Safari or Chrome. Relative link asp.netmvc
- by Ozaki
I have a script that links to the server I am hosting (IP can change) usually I would just use for links:
var url ='http://' + window.location.hostname + 'end of url';
But in this case it isnt appearing to be so easy.
I have tried: (1)
$('#scriptid').attr('src', url);
as well as: (2)
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = url;
$("#insert").append( script );
Now case (2) works loads the script runs the script. But when at the end of my script it hits the 'write data' it decides to replace the entire page with just the data.
Any idea on how I can do this?
Note: I am using plain html not ASP. With ASP backend that is just the way it has to be.
Ok it now is
<script src="myscript.js"></script>
C#
router.AddAsyncRoute("myscript.js"......
It workes in IE & FF. But I get blank pages in Chrome & Safari. I am using document.write to write a script onto my page.
Any ideas why Chrome & Safari don't like this?
I am so far assuming that in Crhome & Safari it takes longer to run the script therefore launching the document.write after the DOM has loaded therefore replacing the page with a blank one.
edit the script im trying to run is a modification of:
d = new dTree('d');
d.add(0,-1,'My example tree');
d.add(1,0,'Node 1','default.html');
d.add(2,0,'Node 2','default.html');
d.add(3,1,'Node 1.1','default.html');
d.add(4,0,'Node 3','default.html');
d.add(5,3,'Node 1.1.1','default.html')
document.write(d);
Any ideas how I can get around this?
I am not to sure how to implement an appenChild in this case as the script is changing constantly with live data. So every refresh it will generally have changed some...