Results 1 to 6 of 6

Thread: Redirect based on browser

  1. #1
    Join Date
    Mar 2003

    Redirect based on browser

    Howdy yall~
    I have a dumb question: I have a code that redirects the user based on their browser and I have it working for IE, Firefox and Chrome but I can not figure out how to make it work any other browsers like Microsoft Edge. Can someone help me out? Great the script was working yesterday for all the browsers now none of them work, what the heck did I do?

    <script type="text/javascript">
        function detectBrowser(){
            var nAgent = navigator.userAgent;
            var verOffset;
                if ((nAgent.indexOf("MSIE"))!=-1) {
                 browserName = "Microsoft Internet Explorer";
                  window.location = "msiebrowser.html";
                else if ((verOffset=nAgent.indexOf("Chrome"))!=-1) {
                 browserName = "Chrome";
                    window.location = "cbrowswe.html";
                else if ((verOffset=nAgent.indexOf("Firefox"))!=-1) {
                 browserName = "Firefox";
                     window.location = "ffbrowser.html";
    Thanks Taz
    Last edited by Tasmanian Devil; 01-29-2016 at 03:21 PM.
    "It is better to keep your mouth shut and look like a fool, rather than open your mouth and be a fool!!!"

    "It is better to say nothing, and be thought a fool, rather than open your mouth and confirm it!!!"

  2. #2
    Join Date
    Oct 2013
    First, Why?? What is so different about those pages that they need to be displayed based on the browser?

    Second, IE >= 10 doesn't ID itself as Internet Explorer (MSIE), so that breaks right away.

    What about Safari?

    What about mobile?

    What about users who choose to not have Javascript running?

    Lastly, and this is a workaround, if you really need different pages for different browsers create an index.xxx with links to those browser-specific pages. For example:
    I am using <a href="ffbrowser.html">Firefox</a>.
    That allows the user to choose their own poison.
    In dog beers I've only had one.

  3. #3
    Join Date
    Mar 2003
    First of all the so much javascript to make things look good on the page and depending what browser they use some of the javascripts work differently in the different browsers, i.e. calendar of events script that I want to use works in all browsers but chrome so I just figured out how to link different pages that work in each browser together.

    I figured that if I had a code in my index page that automatically redirects the user instead of makin em pick a link only if the javascript is not running.

    What do ya think would be the best since ya kinda know what I am trying to achieve

    "It is better to keep your mouth shut and look like a fool, rather than open your mouth and be a fool!!!"

    "It is better to say nothing, and be thought a fool, rather than open your mouth and confirm it!!!"

  4. #4
    Join Date
    Mar 2007
    TBH, pointless because some browsers can be set to masquerade as a different browser.

    Use CSS and conditional elements.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  5. #5
    Join Date
    Nov 2010
    The first thing to do would be to figure out why it is not working in Edge. Is it a javascript problem (have a look at the error console) or CSS drama?

    I think both are somewhat unlikely as Edge is far more standardised than any other IE product but they have probably still left some legacy junk in there just to trip you up.

    Back in the day when browsers were radically different we would use feature detection, not to figure out which browser it was (there are new browsers coming on the market every day, so getting into that hooha will just involve an endless game of catch-up) but to decide which code could be used with the browser in use at the time. This is the only sane approach. As the other two posters have noted, browser sniffing like what you are doing is pointless because you can never trust the results.

    The other thing you want to avoid is having multiple builds of the same page and having to update all of them when you want to make one tweak. Just a recipe for disaster.

    CSS hacks are more reliable but if you think carefully about what you're doing and aren't trying to use anything too hey-hoo-whoopdy-doo are largely unneccesary - most of the CSS hacks out there were implemented for older browsers or by lazy developers.

    Further, "so much javascript to make things look good on the page" is a worrying statement because making things look good is not javascript's job at all really - all that should be done in CSS

    Additionally, if the calendar script is not working in Chrome you REALLY need to find out why, as Chrome is one of the most compliant when it comes to standards and the problem here can only really be either a bum or antiquated script or a poor implementation.

    If it turns out to be the first, you would have the option of fixing it but the reality is that there are a million (I haven't counted them, but let's say) calendar scripts out there. It's quite possible that the easiest solution would be just to find a calendar script that works across browsers and on mobile as well. Any plugin developer worth their name in 2016 is developing with mobile in mind if not as priority number 1

  6. #6
    Join Date
    Oct 2013
    Not much to add to the previous, highly esteemed (and I mean that), respondents. Look, valid HTML and valid CSS should look pretty close to the same cross-browser. It's possible that a CSS rule or three would benefit from a -webkit- vendor prefix to make things look better in Chrome. See shouldiprefix.com, although that list gets smaller seemingly weekly.
    In dog beers I've only had one.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.34680 seconds
  • Memory Usage 2,900KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates