Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check url

Status
Not open for further replies.
Code:
var addr = document.location.href;
var aff = addr.substring("aff=");
var affLength = ("aff=").length;
if(aff.length > affLength && aff.indexOf("&") != affLength)
{
 affHasValue = true;
}

aff.length > affLength indicates that URL string exists beyond the "aff=" in the URL

aff.indexOf("&") != affLength indicates that the URL simply isn't something like "...&aff=&east=east&..."

Of course, this assumes that the URL will always have an "aff=" in it, even if there is no value.

Clunky, but...

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Alternative, do it like this. (sinfo is the value of the query "aff" if there exists; if not it is empty string.)
[tt]
//through assign or other means to retrieve
var surl=" //xyz for testing only

var rx=new RegExp("(\\x3f|\\x26)aff=(.*?)(\\x26|$)");
var cm=rx.exec(surl);
var sinfo=RegExp.$2;
if (sinfo=="") {
alert("no such request variable (aff) or its value is empty");
//do something
} else {
alert("request variable (aff) : " + sinfo);
//do something else
}
[/tt]
 
Excellent worked perfectly. Thanks for your help guys.
 
If you in case use substring() parsing, be mindful of any variables named such as "unaff" or alike. You would better control it like either "&aff=" or "?aff=" to be of more certainty.
 
Hi,

I have hit a problem, I have used the first solution by LFI as there is always an aff in the URL, but where there is aff.indexOf("&") != affLength indicates that the URL simply isn't something like "...&aff=&east=east&..." that doesn't seem to be working as the URL I have tried:


aff is not meant to have a value as & and basically should be disregarded. using my hide method it is actually hiding the div rather than showing it.

Can anyone help
 
I have figured it out, finally, thanks for help anyway.
 
Why is the URL showing &aff= instead of &aff=? Do you have control over the building of the URL?

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top