0

I have a JavaScript file that detects which browser is being used. I'm not sure if this is isn't a proper way to compensate for different browsers, but I'd like to use a different div based on which browser is being used.

I have a very basic page and I'd like to use something like this, but both of my "main" divs are showing up. Is there a way to do this using javascript?

<script> 
 if(BrowserDetect.browser == "Firefox"){
 </script>
 <div id="main_Firefox">
 </div>
 <script>
 }
 else{
 </script>
 <div id="main">
 </div>
 <script>
 }
</script>
asked Oct 2, 2012 at 0:35
3
  • What exactly are you trying to do, could you expand a bit more? Commented Oct 2, 2012 at 0:39
  • Take a look at this: How to display browser specific HTML?. Basically it is not a good idea to do what you described. Commented Oct 2, 2012 at 0:40
  • I'd like to use a different div based on which browser is being used. Firefox is rendering one of my divs lower than other browsers. I was told by @Steven to check out conditional tags. Commented Oct 2, 2012 at 0:40

1 Answer 1

2

You never want to have something like this, you should use one HTML system for everything. And use CSS and conditional tags in CSS to solve any cross browser issues.

Also you shouldn't rely on user agent strings to determine a browser.

answered Oct 2, 2012 at 0:38
Sign up to request clarification or add additional context in comments.

3 Comments

So, you suggest I investigate CSS conditional tags? Sorry, I'm new to this.
You could also look into something like modernizr, which adds css classes to your body tag based on features available. Anymore these days people are suggesting detecting features and not browsers for a vast number of reasons.
Well I suggest you take a look at quirksmode.org/css/condcom.html but really it depends on what you need.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.