Click to See Complete Forum and Search --> : n00bish JS link editing Question


SDaddy
04-25-2003, 12:24 AM
Some Background First: On a website, I have a custom 404 error page via .htaccess, nothing special.

The Problem: That page happens to be appearing far too much

The Reason: The URL Frame automatically generated by the server (a URL Frame allows an input URL through a link or a browser location bar in the form http://site.com/whatever , which opens the real URL location in an invisible frame: http://realsite.com/site.com/whatever . Of course the site.com form looks far better than giving the actual URL, and is shorter too, so it;s much easier for the user to use it and type it.) doesn't work very well and often fails. It just so happens that you never see 404s if you enter in the real URL.

The Compromise: I really don't want to link to the real URL, so I decided whenever a 404 comes up, the user can just click on a link to the real URL and they will be where they want to go.

The Solution: I was thinking that maybe if I could get some JavaScript on the 404 page to read the referrer URL (i.e. in http://site.com/whatever/ form) and alter it to the real URL, which it displays as a link, "were you trying to go here?"

The... Other Problem: I stink at JS and have no idea how. I was told this would be a pretty simple script, but I can't do it.


Can somebody give me a hand?

DrDaMour
04-25-2003, 03:00 AM
this shoudl work for you, modify the URLS



<script>

if("badurl" == window.location){
document.wirte("Since you tried to go to " + window.location + " I'm sending you to URLTOGOTO");
window.location.href = "urltogoto";
}


</script>

SDaddy
04-25-2003, 04:39 PM
Hmm... but what I want is for the 404 page to read the URL of the page that didn't work which sends the user to the 404 page (http://site.com/whatever) and write on the 404 page a link to http://realsite.com/site/whatever

So in other words, it has to read the referrer's URL, and output the proper URL. Is this easily possible?

SDaddy
04-26-2003, 11:18 AM
bump :)

khalidali63
04-26-2003, 11:29 AM
There are some apprehensions about the
referrer method.It is webserver depenedent.And it does not work for all the time.
The best that I can think of is you pass the error originating pages url to the 404 response page...adn on that page parse the url and then create a link ...etc..

Make any sense?