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!

IndexOf Ampersand

Status
Not open for further replies.

sagamw

Technical User
Nov 11, 2009
104
GR
Hi guys,
I m trying a simple script for greasemonkey/firefox and I have some problem with & (ampersand)

Code:
var links = document.links;

for (var i = 0; i < links.length; i++) {
    var link = links[i];

    	var linkString = link.toString();
	var indexOff = linkString.indexOf('&');

        if (indexOf > 0) {
	link.href = linkString.substring(0, indexOff);
	}
}

As you can see I am trying to cut the part of the url after the &

For Example a link like this:
I want to do it like this:

The code works for all the characters/strings I tried includin the question mark, but It doesn;t work as it for &.

So far I tried some alternatives
var indexOff = linkString.indexOf("&");
var indexOff = linkString.indexOf(%26);
var indexOff = linkString.indexOf("&amp");
etc..
but with no luck :-(

What is the correct syntax for this?
TIA
 
I don't see anything special.
>if (indexOf > 0) {
[tt]if (indexOf[red]f[/red] [red]!= -1[/red]) {[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top