开发者

Want to set 'src' of script to my IP-Won't load in Safari or Chrome. Relative link asp.netmvc

I have a script that links to the server I am hosting 开发者_如何学JAVA(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.

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...


So setting the Route actually does work perfectly fine.. I was having issues with loading it not because of my document.write yes i know its nasty but because Skype was hogging port 80 but only for Safari and Chrome because I had been using FF & IE before skype started. So a simple disable of letting skype have port 80 in connection options and the

<script src="myscript.js"></script>

&

router.AddAsyncRoute("myscript.js"......

Work perfectly fine ^^

So the question still remains as I would still like to find out (if possible) how to set the 'src' tag of a script to a variable or so?


Don't use absolute paths (domain name, IP). Just use the relative path to your script and you're good. Then you won't have to do any of this replacing etc. For instance if your script is called my_script.js don't use src="http://...my_script.js" use src="my_script.js".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜