Closed Thread Icon

Preserved Topic: Match Any Part of location.href Pages that link to <a href="https://ozoneasylum.com/backlink?for=8532" title="Pages that link to Preserved Topic: Match Any Part of location.href" rel="nofollow" >Preserved Topic: Match Any Part of location.href\

 
Author Thread
Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 02-16-2003 06:37

I've recently decided to begin allowing more leeway with translation sites that access my sites' pages. In addition to allowing them access to my images, I've also decided to allow some of the more popular translation sites to remain in frames for clarity and ease of use for non-English-speaking readers.

In order to make exceptions in my frame busting, I need to detect and match the URLs. With one in particular, I find it will be easier to detect a certain part of the location.href appearing anywhere in the URL.

I know how to use document.location.pathname.substring(#,#) as well as document.location.href.substring(#,#). The problem with these, however, is that I have to specify exactly where the matching string appears in the sequence.

How can I specify a string (e.g. "translation") and search for it anywhere in document.location.href? (All I need to do is return a value of true if it's found.)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 02-16-2003 07:00

document.location.href.indexOf('translation');

This actually returns The first location of the string. But as long as it's positive it returns true.



.:[ Never resist a perfect moment ]:.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 02-16-2003 07:13

Strictly speaking, document.location.href doesn't exist, since document.location is different from window.location, and window.location is the one that has properties like href. (document.location, I believe, is nothing more than a string.) If I'm right (and I might be remembering wrong), document.location.href is only working because the browser is being nice to you. =)

What bitdamaged posted will return -1 if the substring doesn't exist in the string. So you can compare it against -1, and if it's != -1, then you know the string was found.

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 02-18-2003 16:19

aw, damn... I thought there'd be something about regexp's in here...

don't play with a man's mind like that!


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

trib
Paranoid (IV) Inmate

From: Den Haag, Netherlands
Insane since: Sep 2002

posted posted 02-19-2003 16:40

Ahaaa .. a masochist unmasked ... HEY EVERYONE .. this guy actually WANTS to use regexps !!!! ..

and only 2 minutes after I wrote a reply to http://www.ozoneasylum.com/Forum2/HTML/002025.html and hoped I hadn't made TOO much of a fool of myself


[This message has been edited by trib (edited 02-19-2003).]

« BackwardsOnwards »

Show Forum Drop Down Menu