SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    delaware
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ok I admit it, but need help

    Alright, I admit that I have no clue how to create web pages, but I need some help that may piss you guys off. How do I allow one specific browser to view a web page, but not any other browser?

    The skinny of it is that I created a site for work that I'm pretty proud of to be honest, but I broke every web development rule known the man. It looks great in all versions of Firefox, but IE, remember in Rudolph the Red-Nosed Reindeer when they come back from showing the bumble for the first time? Well I'm the snowman(Sam by the way, why do I know that?) hiding behind the umbrella when looking at this site in IE. Some of the other guys here use Safari and Opera as well.

    All joking aside. I really don't know that much HTML, but I'm creating a site for work that is only intended for about 10 people, but it only displays correctly in Firefox. I know you're going to say I should learn the correct way, but to be honest I want to see how the site takes off before I go and learn any more of the web technology. I was hoping on page load I could determine the browser and if it's not Firefox then display a custom error page. I know the page can be loaded in manually, but I'm not worried about that.

    Can or will you guys help me out?

  2. #2
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by notta View Post
    but I need some help that may piss you guys off. How do I allow one specific browser to view a web page, but not any other browser?
    You are right, that will piss off a few people here. Good news is it can be done, bad news is that you can't do it with HTML. You will need to add Javascript to your skillset (this can be done on the server as well but JS is easier).
    The skinny of it is that I created a site for work that I'm pretty proud of to be honest, but I broke every web development rule known the man.
    Then you probably shouldn't be all that proud of it. Then again, we all start somewhere. So I shall assist you in your nefarious goal.

    Add something like this to the body tag in your page:
    Code:
    <body onload="sniff();">
    And somewhere between the head tags:
    Code:
    <head>
    ...
    <script type="text/javascript">
    function sniff() {
       if(!navigator.userAgent.match(/firefox/i)) {
          // delete everything
          var body = document.body;
          while(body.firstChild)
             body.removeChild(firstChild);
          
          // pimp for mozilla
          var anchor = document.createElement('a');
          anchor.href = 'http://www.mozilla.com/en-US/firefox/';
          anchor.appendChild(document.createTextNode('Download FireFox!'));
          body.appendChild(anchor);
       }
    }
    </script>
    ...
    </head>
    Cheers,
    D.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    delaware
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man. I understand exactly what you're saying, but I'm learning 100 different things right now so I need to pick my battles. If my boss and co-workers find this useful than I'm sure to bump this up in the priority list. As for the code, it didn't work. The directions were great and I placed it correctly, but the I see the horrid in IE when I load the page. Any ideas?

    Edit:

    Error log in IE6 shows "Error 'firstChild' is undefined"
    Code: 0

  4. #4
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops. That should be
    Code:
    body.removeChild(body.firstChild);
    Next time I'll just copy & paste the test code.

    Cheers,
    D.

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    delaware
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep that did it. Here were the results:

    IE6 on one machine still displayed the page with the active-x warning. When I allowed active-x the page disappeared and showed the Firefox link.

    IE6 on a second machine flashed the page real quick, but showed the link with no warnings. Could make out just shapes in the flash.

    Opera flashed the page as well, but then showed the link. Could only make out shapes in that split second. This was the first time even checking with Opera and the page itself looked the way it should except for a couple small things. I could live with it.

    Safari actually looked better than Firefox. Something about the colors or something, but I'm going to encourage the use of Safari now

    So, I guess I didn't break as many rules as I thought, but unfortunately IE is still probably the most dominant and there is no mistaken that it looks like a train-wreck in IE.

    Thanks for coming to the dark-side and helping me out

  6. #6
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suppose while we're in the Dark Lord's terrain, the lesser of the evils would be a meta redirect:
    Code:
    <head>
       ...
       <meta http-equiv="refresh" content="0;url=http://your.domain.com/getfirefox.html">
       ...
    </head>
    It will avoid that momentary flicker of FF-only content. Don't know why I didn't suggest this in the first place.

    Cheers,
    D.

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by disgracian View Post
    Don't know why I didn't suggest this in the first place.
    Conscience?!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha! My conscience should have knee-capped me long before I got to the meta redirect.

    Cheers,
    D.

  9. #9
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    delaware
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D, I'm not exactly sure what this does. Is this used in conjunction with the javascript you posted? When adding this nothing seems to work now. Can you explain it? Thanks.

    Quote Originally Posted by disgracian View Post
    I suppose while we're in the Dark Lord's terrain, the lesser of the evils would be a meta redirect:
    Code:
    <head>
       ...
       <meta http-equiv="refresh" content="0;url=http://your.domain.com/getfirefox.html">
       ...
    </head>
    It will avoid that momentary flicker of FF-only content. Don't know why I didn't suggest this in the first place.

    Cheers,
    D.

  10. #10
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, you'd dump the Javascript if you used that.
    Code:
    http-equiv="refresh"
    This refreshes (ie, reloads) the page.
    Code:
    content="0;url=http://your.domain.com/getfirefox.html"
    The 0 indicates after a delay of 0 seconds (immediately), and after the semicolon is the URL of the page to load instead of the current page, which you would point to a custom error page with a link to Firefox.

    It should eliminate the momentary flicker and allow you to make a nicer error page.

    Cheers,
    D.

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)
    If it's not that you want to limit viewing to only 1 browser, but that you want to exclude only IE, try conditional comments.

  12. #12
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    delaware
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's not that you want to limit viewing to only 1 browser, but that you want to exclude only IE, try conditional comments.
    Thanks guys. Yes conditional statements is probably the way I would want to go because it seems to be working the way I want in everything but IE.

    Yeah, you'd dump the Javascript if you used that.
    D, if I was to dump the Javascript, how would the new code you posted test for the browser? I removed the javascript and inserted the redirect code you posted, but "all" browsers now redirect to the url specified. Even with the new code there is still a flash, enough to see the page during the flicker

    I would imagine using the second code D posted with the conditional statements would do exactly what I need. I'm sorry, but javascript is a very cryptic looking language.

  13. #13
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by notta View Post
    D, if I was to dump the Javascript, how would the new code you posted test for the browser?
    With the conditional statements that, as it turns out, I forgot to mention. Sorry about that.

    Cheers,
    D.

  14. #14
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by disgracian View Post
    Then again, we all start somewhere. So I shall assist you in your nefarious goal.
    hehe, I felt all dirty just reading this thread...


Bookmarks

Posting Permissions

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