Live Chat Icon For mobile
Live Chat Icon

Can I access the query string using JavaScript?

Platform: ASP.NET| Category: Client Side Scripting

A query string is an optional part of a URL that goes after the file name and begins with a questionmark.

For eg the query string will be as

http://www.sitedemo/com/home.htm?newquerystringadded.

Here querystringvalue is the newquerystringadded.

The query string can be added and it can be retrieved as shown,


<div>
	<input type=button value='AddQueryString'  
	 onClick='self.location=
	self.location.protocol+’//’
	+self.location.host
	+self.location.pathname+’?addquerystring’'>
	
	<input type=button value='ShowQueryString' 
	onClick='alert(’Query string Value: ’+self.location.search)'>
</div>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.