window.location help, please

J

JW

Long story, but I manage the website for a local Red Cross chapter. They
have their own domain name, but it points to a url on the National ARC
servers. The forwarding service is not masked, so there is concern that many
visitors have bookmarks to the actual url's for various pages.

Several chapters are merging their websites, so the domain name forwarding
is being re-directed to a new url. The old url server space will remain
available for awhile. I want to use {{
window.location.href="http://www.newurl.com"; }}on the Home page of the old
site to convey any viewers to the new Home page. However, the website has
LOTS of pages and it's likely that many of the interior web pages are also
bookmarked by viewers. Am I required to insert this code on every page, or
is there a clever way to redirect viewers to *any page* for a specific url?
Sounds like a pipe dream, but thought I'd ask before starting. Thanks for
your help,
JW
 
T

Trevor Lawrence

JW said:
Long story, but I manage the website for a local Red Cross chapter. They
have their own domain name, but it points to a url on the National ARC
servers. The forwarding service is not masked, so there is concern that
many visitors have bookmarks to the actual url's for various pages.

Several chapters are merging their websites, so the domain name forwarding
is being re-directed to a new url. The old url server space will remain
available for awhile. I want to use {{
window.location.href="http://www.newurl.com"; }}on the Home page of the
old site to convey any viewers to the new Home page. However, the website
has LOTS of pages and it's likely that many of the interior web pages are
also bookmarked by viewers. Am I required to insert this code on every
page, or is there a clever way to redirect viewers to *any page* for a
specific url? Sounds like a pipe dream, but thought I'd ask before
starting. Thanks for your help,
JW

This seems to be a javascript question

I had a similar problem in that I wanted to redirect from
http://url1.net/ratec/page1.html
to
http://ratec.actbus.net/page1.html
(The value of url1 is not important, but each page in the site has different
names)

I placed this code in the <head> of each page:
<script src="scripts/redirect.js" type="text/javascript"></script>

This is scripts/redirect.js

/* redirect.js */
function relocate() {
var href = location.href;
var ix = href.indexOf('.net/ratec/');
if (ix != -1) {
location.href = "http://ratec.actbus.net" + href.substr(ix+10);
}
}
relocate()

If each page in the website already has a reference to a common JS file (say
external .js) then the above code could be added into the top of that file.
One would have to take care that the string being tested for does not also
occur in the new href name or it will continually attempt to reload itself.
This might mean that the code would look something like (not tested)

function relocate() {
var href = location.href;
var ix = href.indexOf('.oldurl.com/');
if (ix != -1) {
location.href = "http://newurl.com" + href.substr(ix+11);
}
}
relocate()

oldurl and newurl are replaced by the actual names, but the number in
"substr(ix + ..)" needs to be adjusted accordingly It is one less than the
length of the string being tested

This may work for you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top