Jump to content

Javascript get URL thing


kanala

Recommended Posts

Is it possible to use javascript to retrieve information from the URL? Like you can do with PHP e.g. www.google.com/index.php?id=41Does javascript have that ?id thing?I need it because I want to make a shop using html and javascript only, as my host does not allow php. What I need is e.g. if id = 41, then the page is linked to another javascript page named 41.jsThanks

Link to comment
Share on other sites

Thanks, so if I wanted to change the src to the window.location.search would I do:<script src="window.location.search + '.js'" type="text/javascript"></script>It needs to end in .js

Link to comment
Share on other sites

If you wanted to change the src to window.location.search, then yes, that is what you would do. That would only be a valid filename though if you only had one parameter on the querystring and it didn't have a value, e.g. index.html?41. Also, I'm pretty sure that the search property includes the question mark, so you would want to strip that out first.http://www.w3schools.com/htmldom/prop_loc_search.asp

Link to comment
Share on other sites

I don't know who made this function, and I have never test it, but i think it will work.

<script type="text/javascript">//The functionfunction getFormValues() {   var search = window.location.search.substring(1);   var pairs = search.split("&");   var ret = new Object();   for(var pair in pairs) {	  ret[pairs[pair].split("=")[0]] = pairs[pair].split("=")[1];   }   return ret;}//Have this to call the function_GET = getFormValues();//_GET is now an array with the values of the querystring, just like in PHP.//Example of using:alert(_GET['name']);</script>

Maybe this isn't what you seek, but it may become useful. The code above is from PHPportalen (Sweden) (http://www.phpportalen.net/viewtopic.php?p=400967#400967), if anyone care.

Link to comment
Share on other sites

Hi you can do it with these steps.

<script language="javascript">  var myURL = document.URL;</script>

then in variable myURL you can fine the character ? and onward so you have to split manually ur variables and its values.Last thing on next page you can't get the variable values in JavaScript here you need to use PHP or ASP.ThanksAli.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...