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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

url string manipulation 2

Status
Not open for further replies.

machine08

Technical User
Dec 16, 2007
22
0
0
US
Hi all,

I'm having a hard time understanding how to compare url strings. Here's my scenario:

I have a button in my page that redirects user to another page. I would like to grab that url string and compare it with the url of the actual page the user is in. If I do an onclick event on the button I can get this url string:
Code:
function getButtonURL(x){
	var buttonURL= window.location.href;
	alert ("The button's URL is: " + buttonURL);
	}

If I do a global call for the page's URL I can also get that string:
Code:
var URLString = window.location.href;
alert (URLString);

The order these alerts happen is first the button URL then the current page URL.

My issue is grabbing both of those values and passing them unto a function to compare them. Could someone please advice how to go about doing this.

Thank you in advance!
 
I don't understand your question. You are storing window.location.href in 2 different variables, and you want to compare those 2 variables? They will always contain the same content if they are called from the same page.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Sorry I I did not explain myself well. What I want to compare is the window.location.href of the page with a button that redirects that page. I want to compare those 2 URL and do some string manipulations before redirecting the user.

I.E. window.href.location is
there's a button in the page that will redirect the user to:
When user clicks on the button I would like to do the following:

Grab and and compare the strings. Then come up with a new URL and redirect the user to that URL.

Does that make sense? Thank you!
 
Is this the kind of thing you are looking for?
Code:
function checkURL(link) {
 var linkLocation = link.href;
 var windowLocation = window.location.href;
 alert(linkLocation + "\n\n" + windowLocation);
}
...
<a href="[URL unfurl="true"]http://www.google.co.uk"[/URL] onclick="checkURL(this);return false;>Google</a>
Obviously you wouldn't just alert the result like I have [smile]

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
OK let me give more details about the requirements. The current page might have a parameter in the url (ie. ?Area=US)

If there is a parameter in the current page and a user clicks on the button, I would like to pass this parameter to the button as well. Does this make sense?
 
If there is a parameter in the current page and a user clicks on the button

Is this button an anchor (<a href....), a javascript button (<input type="button".....), or a submission button (<input type="submit"....) ?

There may be an easy answer depending on which type of button it is.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Hi Kaht. This would be an anchor. Thanks!
 
machine08 - check my response a few posts back in this thread (you may have missed it).

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hi Kaht. This would be an anchor. Thanks!

Then you'll want to follow Jeff's advice from his post above.

The reason I said that it made a difference is that if you are submitting a form then you can leave the action attribute blank and it will submit back to the page it was submitted from, including all the items in the querystring.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Kaht and BabyJeffy. Thank you both for your guidance and explanation. BabyJeffy, that worked great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top