Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The JavaScript FAQ
Prev Home Next

Query Strings

Question: Can my script access the query string in the current URL?

Answer: A query string (or search string) is an optional part of a URL that goes after the file name and begins with a question mark (?). For example, the following URL has a query string ?myquery after the HTML file name:

https://www.myfirm.com/file.html?myquery
Your script can access the query string in the current URL by using the JavaScript location.search property. Click the buttons below to try it! (To view the URL in the address line, you might want to display this page in the top-level browser window.)
These buttons have been created using the following code:
<form>
<input type=button value="Add query ?test"  
onClick="self.location=
self.location.protocol+'//'
+self.location.host
+self.location.pathname+'?test'">

<input type=button value="Show query" 
onClick="alert('Query string: '+self.location.search)">

<input type=button value="Remove query" 
onClick="self.location=
self.location.protocol+'//'
+self.location.host
+self.location.pathname">
</form>
NOTE: query strings may not always work as expected. For example, if you save this page on your local disk, the above buttons won't work in Internet Explorer 4.x (but they would still work in Netscape Navigator).

JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next


 
 
  Mirrored with kind permission of Alexei Kourbatov Design by Interspire