Quote:
Question...not sure if this is a javascript question or not.
I've set up a redirect with javascript that works fine. My question is, someone mentioned that I can control that url somehow, possibly with js. For example, let's say I'm redirected yahoo.com to google.com. Supposedly, once the site redirects there's a way to have the url still show yahoo.com
Is this possible with javascript or something else?
|
Quote:
Originally Posted by Philip M
No. that would be dishonest, wouldn't it? That's what phishing sites try to do. Modern browsers block that kind of malarkey.
|
to note, and i'm not suggesting this as an ideal solution, but this sort of thing is possible, more so in modern browsers, given co-operation by both sites.
the old-school way to do it is with an iframe. you can place it edge-to-edge in css. the frame points to the long url, while the short url serves a shell page with little more than the iframe tag. the main downside to this technique is that the address bar does not change when the framed page navigates.
newer browser features provide better ways of doing this.
see
http://diveintohtml5.info/history.html
and
https://developer.mozilla.org/en-US/...rowser_history
for details.
in newer browsers, you can actually update the full path in the url bar, not just the hash (#top).
even in ie8, you can use a hashChage and update "fragment" urls, not ideal but better than the nothing provided by the old-school technique.
one simple method, used in conjunction with the regular iframe, is to have clicks sent up to the top using top.postMessage() to set the user's url bar to the url of the frame.
a better but more complex method, is to use ajax to fetch a relative url from the long-url site instead of framing the long-url site. This means computerconnection.sandbox.computers.com must emit Access-Control-Allow-Origin headers set to "computerconnection.com" or "*".
in this fashion, you can bind nav-canceling click handlers to the A tags, call pushState(this.href) instead, and in your
onpopstate() event, use ajax to fetch the relative url :
location.href.split(document.domain)[1]
from the remote site. Grab the html, parse it, update the body's innerHTML, re-bind all A tags, update the document.title, and set any classes on the html/body tag (if needed) with the new page's values.
presto-change-o: navigate a remote site with javascript, back and forward work, as do bookmarks, and it can get even better from there.
if 40% of your visitors hit 5 pages, perhaps you might consider downloading those page's urls in the background once the landing page is loaded. it's quick because you only download the html, you don't have to render css, parse scripts, etc. if your ajax routine caches urls into ram, a click to those pages renders dang-near instantly.
anyways, again, i know this is a bit much for the OP, but it's something to keep in mind as a production-ready possibility. for a full site, i would rather switch the dns, but for cloning a smaller event sub-site or something like that, it's workable in the here and now.