/    Sign up×
Community /Pin to ProfileBookmark

location.href problem

When surfing for one of my websites I sometimes see individual pages from those websites being displayed. At first glance you would think it was the website as the displayed <title> is the same.

When you click on one of these pages you only get that page. My problem is to redirect that click to the websites index.html.

The folowing function is triggered by an onLoad in the <body>

[COLOR=”darkred”]<SCRIPT type=”text/JavaScript”>
function wrongurl() {
if (location.href!=’http://www.elitestairways.com/index.htm‘)
location.replace(‘http://www.elitestairways.com/index.htm‘)
}
</script>[/COLOR]

if (location.href is not the correct url)
then
location.replace(with correct url)

This works very well in my editor but online it just loops and eventualy crashes IE.

Got any ideas please..

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jun 29.2009 — Maybe:

[CODE]if (window.location.href.toLowerCase()!=='http://www.elitestairways.com/index.htm')[/CODE]

Eric
Copy linkTweet thisAlerts:
@glenvernauthorJun 29.2009 — Thanx alien - It did the same, stuck in a loop.
Copy linkTweet thisAlerts:
@A1ien51Jun 29.2009 — what does it say the window.location.href is when the page reloads?

Eric
Copy linkTweet thisAlerts:
@glenvernauthorJun 30.2009 — Address bar reads correct website url

Status bar reads page url and is looping in the page frame
×

Success!

Help @glenvern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...