Jump to content

querrystring into a javascript


netcracker
 Share

Recommended Posts

how could i get a value from a querrystring (in the address) into a javascript??like the expression request.querrytring, just that it should be in JavaScript.eg:www.site.com?string=valuehow could i get the "value" to be used with a javascript in a *.js file !hope i've made myself clear, though it is quite difficult to explain.

Link to comment
Share on other sites

/* Client-side access to querystring name=value pairs	Version 1.2.3	22 Jun 2005	Adam Vandenberg*/function Querystring(qs) { // optionally pass a querystring to parse	this.params = new Object()	this.get=Querystring_get		if (qs == null)		qs=location.search.substring(1,location.search.length)	if (qs.length == 0) return// Turn <plus> back to <space>// See: [url="http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1"]http://www.w3.org/TR/REC-html40/interact/f...tml#h-17.13.4.1[/url]	qs = qs.replace(/\+/g, ' ')	var args = qs.split('&') // parse out name/value pairs separated via &	// split out each name=value pair	for (var i=0;i<args.length;i++) {		var value;		var pair = args[i].split('=')		var name = unescape(pair[0])		if (pair.length == 2)			value = unescape(pair[1])		else			value = name				this.params[name] = value	}}function Querystring_get(key, default_) {	// This silly looking line changes UNDEFINED to NULL	if (default_ == null) default_ = null;		var value=this.params[key]	if (value==null) value=default_;		return value}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...