Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Thanked 0 Times in 0 Posts

    Javascript to make the div visible in IE


    I was wondering if anybody knew the proper coding in order to make a Div visible if the users browser is IE?

    I have a situation on my site that involves an iframe opening inside a hidden div on hover. Apparently there is a hover bug in IE that doesn't allow this action.

    I have read the solution is;

    The IE7 :hover bug can be mitigated by placing a hidden div behind the element. Use javascript to make the div visible if the browser is IE 7. The div needs to be wider & higher than the element and must have a background-color. Add filter: (opacity=1) if you don't want the div to be seen.

    The net result here is that when the mouse is moved from element it hits the div, which fires the mouseout event (removes the :hover alteration).

    Remember to hide the div again on mouseout.
    Does anybody know how this is done?

    Thanks in advance, any help is appreciated!

  2. #2
    Registered User
    Join Date
    Oct 2004
    Thanked 1 Time in 1 Post
    <div id="eg"></div>

    document.getElementById('eg').style.display = 'block';
    document.getElementById('eg').style.visibility = 'visible';

  3. #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts
    If you want something visible only in IE then set it as hidden in the stylesheet and then you can the following code to make it visible in IE (which runs JScript instead of JavaScript and therefore understands JScript conditional comments):

       @if (@_jscript) 
           document.getElementById('eg').style.visibility = 'visible';
    @end @*/
    If you specifically need to test for IE7 then add a test for @_jscript_version >= 5.6 to the if statement.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


Posting Permissions

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