Jump to content

JavaScript URL


DaNuGai

Recommended Posts

Is is possible to check the URL depending on the URL Change the SCRIPT SRC???In other words: if the URL is http://192.168.1.152/, then the Script SOURCE should be....<script LANGUAGE="JavaScript" SRC="http://SOMEWEBSITE/source.js"></SCRIPT>but if the URL is http://SOMEDOMAIN.com/, then the Scipt SOURCE should be...<script LANGUAGE="JavaScript" SRC="http://OTHERWEBSITE/source.js"></SCRIPT>I would really appreciate some help. Thanks in advance.

Link to comment
Share on other sites

The way you could do this so that it acts consistently across all browsers would be to use a server-side solution (PHP, ASP.NET, CF, etc., etc.) to determine the domain and then write out the appropriate path to send to the client.In ASP.NET (C#) it could look something like:

<script type="text/javascript" src="<%= Path %>"></script>

Then, on the server, you would set the "Path" variable depending on where the request is coming from.If, on the other hand, you are limited to using client-side javascript, you could try something like this (haven't really tested this too much):

<script type="text/javascript" id="included"></script><script type="text/javascript">var src = "";var url = location.href;if(url.indexOf("192.168.1.152") > -1){	src = "http://SOMEWEBSITE/source.js";}else if(url.indexOf("SOMEDOMAIN.com") > -1){	src = "http://OTHERWEBSITE/source.js";}var included = document.getElementById("included");if(included){	included.src = src;}</script>

Link to comment
Share on other sites

or you can do it this way :)
<script LANGUAGE="JavaScript" SRC="/source.js"></SCRIPT>

/source.js means whateverdomain/source.js

:)As long as the domain in the URL is supposed to match the domain in the script's URL. I read, in the example, that the domain would not necessarily match the domains for the pages.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...