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 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    object required, dunno how to solve

    Hi got this little script, which should display a div if the browser is IE. However I get an 'object required' error at the
    document.getElementById( "dhtmlEl" ).style.visibility = 'visible';
    line. What do I have to change to make it work ?

    <html>
    <head>
    <script type="text/javascript">
    var browser=navigator.appName
    var b_version=navigator.appVersion
    var version=parseFloat(b_version);
    if(browser=='Microsoft Internet Explorer'){
    document.write("Browser name: "+ browser)
    document.write("<br />")
    document.write("Browser version: "+ version)
    document.getElementById( "dhtmlEl" ).style.visibility = 'visible';
    }
    </script>
    </head>
    <body>

    <div id="dhtmlEl" style="visibility: hidden;">
    <a class='green' href="javascript:bookmarksite('MSNEMO','http://www.msnemo.com');">Click here to bookmark msnemo</a></center><br><br>
    </div>

    </body></html>

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    you have to set it up as a function and call it on body onLoad="" like this:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function showApp(){
    var browser=navigator.appName
    var b_version=navigator.appVersion
    var version=parseFloat(b_version); 
    if(browser=='Microsoft Internet Explorer'){
    document.write("Browser name: "+ browser)
    document.write("<br />")
    document.write("Browser version: "+ version)
    document.getElementById( "dhtmlEl" ).style.visibility = 'visible';
    }
    }
    </script>
    </head>
    <body onLoad="showApp();">
    <div id="dhtmlEl" style="visibility: hidden;">
    <a class='green' href="javascript:bookmarksite('MSNEMO','http://www.msnemo.com');">Click here to bookmark msnemo</a></center><br><br>
    </div> 
    
    </body></html>
    Last edited by boeing747fp; 08-01-2006 at 09:11 AM.

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,468
    Thanks
    3
    Thanked 495 Times in 482 Posts
    document.write can only be used as page first rendered
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function showApp(){
    var browser=navigator.appName
    var b_version=navigator.appVersion
    var version=parseFloat(b_version);
    var string='';
    if(browser=='Microsoft Internet Explorer'){
     string+=("Browser name: "+ browser)
     string+=("<br />")
     string+=("Browser version: "+ version)
    
     document.getElementById('fred').innerHTML=string;
     document.getElementById( "dhtmlEl" ).style.visibility = 'visible';
     }
    }
    </script>
    </head>
    <body onLoad="showApp();">
    <div id="fred">
    </div>
    <div id="dhtmlEl" style="visibility: hidden;">
    <a class='green' href="javascript:bookmarksite('MSNEMO','http://www.msnemo.com');">Click here to bookmark msnemo</a></center><br><br>
    </div>
    
    </body></html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    lol i originally posted that but i was having problems getting it to work myself... and i was just gonna post an update

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function showApp(){
    var browser=navigator.appName
    var b_version=navigator.appVersion
    var version=parseFloat(b_version); 
    if(browser=='Microsoft Internet Explorer'){
    document.getElementById('main_div').innerHTML="Browser name: "+ browser + "<br />" + "Browser version: "+ version;
    document.getElementById( "dhtmlEl" ).style.visibility = 'visible';
    }
    }
    </script>
    </head>
    <body onLoad="showApp();">
    <div id="main_div"></div>
    <div id="dhtmlEl" style="visibility: hidden;">
    <a class='green' href="javascript:bookmarksite('MSNEMO','http://www.msnemo.com');">Click here to bookmark msnemo</a></center><br><br>
    </div> 
    
    </body></html>
    which is the same thing as vwphillips posted :P

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, aint getting the errormessage anymore and the browser name is displaye, however the div aint displayed

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    it worked for me

  • #7
    New Coder
    Join Date
    Aug 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    seems to work indeed thank you very much


  •  

    Posting Permissions

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