Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Control Redirected URL with Javascript?

    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?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by javanewbie7 View Post
    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?
    No. that would be dishonest, wouldn't it? That's what phishing sites try to do. Modern browsers block that kind of malarkey.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Yes it would. Except, this is a more legitimate reason. Sorry, I gave a poor example.

    The home office of the company that I work for is offering to host our website (all content, video, images, etc.). I would still manage the website, but I wouldn't have to worry about the backend. So if we do that our url would be something like computerconnection.sandbox.computers.com. Rather than that, we want it to just be computerconnection.com.

    That said, if modern browsers block it, that's good to know. Thanks.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    ??? Why does it matter whether the home office hosts the site or some third party hosts it?

    There's nothing illegitimate about having multiple domains point to the same IP address.

    Just ask the home office to give you the IP address and then you can go to your domain registrar (the place you bought your domain name) and set up your domain's "A" records to point to that IP address.

    Now, if your home office only has one IP address available, then if they had "www.homeoffice.com/index.html" and somebody browsed to your site's "www.computerconnection.com/index/html" you would actually end up getting the home office's web page. So ideally you would like them to be able to assign you to your own ip address. But failing that, they could assign you to a subdirectory. I've had a few funny experiences when assigned to a subdirectory (having to do with the subdirectory name showing up in the URL, which is less than desirable), but there are easy ways to work around that.

    I actually use GoDaddy for my personal hosting and I have 13 different domains assigned to my one GoDaddy account and thus to one IP address and it works just fine. But I also manage a site that has 15 ip addresses all on one server and that also works just fine.

    Work with your home office. They should be able to set you up just fine.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    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 View Post
    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.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I don't really understand all that, but my position is that is it deceitful and dishonest to pretend to a user that he is visiting a certain web page when in reality he is visiting another. I can think of no situation where that is proper or legitimate, and as I see it that is a technique of phishers and other criminals. That is not at all the same as having multiple domains point to one IP address. I don't think that sort of thing ought to be encouraged in this forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by Philip M View Post
    I don't really understand all that, but my position is that is it deceitful and dishonest to pretend to a user that he is visiting a certain web page when in reality he is visiting another. I can think of no situation where that is proper or legitimate, and as I see it that is a technique of phishers and other criminals.
    guns don't kill people, people kill people. i do think that guns often help to kill people, but let's not go there...

    the pattern is actually quite common: youtube's related videos after watching a full-screen embed, disqus's paginated comment pages, modal dialogs that allow iframes, etc.

    it can be quite useful in many situations.

    -as a dev mechanism to replace html tags on-the-fly and preview changes.
    -display a navigable site while playing uninterrupted audio, radio streaming for example
    -used in conjunction with the fullscreen API to offer "what now?" possibilities upon task completion
    -re-format an existing site into bare html to assist screen readers and other A.T.
    -apply a mobile skin to an existing site without touching each page of the old site
    -to showcase a "project site" from a portfolio site without ugly frame borders
    -works with <noscript><iframe> to allow legacy support in above situations
    -allows performance-enhancing pre-fetching opportunities
    -allow new possibilities like serving a navigable site from a zip file.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by rnd me View Post
    guns don't kill people, people kill people.
    <rant>
    I am always angered when I see one of the silliest and most childish sophisms ever. The average American is 40 times more likely to be killed by gunfire than the average Englishman or Canadian. According to the NRA, this has nothing to do with the fact that guns proliferate in America and are scarce in England and Canada. We just have to face the facts: Americans, unlike Englishmen and Canadians, are murderous by nature. The ready availability of assault weapons in Walmart has nothing to do with it.
    </rant>

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •