Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-01-2006, 08:59 AM   PM User | #1
cooldaddy
New Coder

 
Join Date: Aug 2005
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
cooldaddy is an unknown quantity at this point
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>
cooldaddy is offline   Reply With Quote
Old 08-01-2006, 09:04 AM   PM User | #2
boeing747fp
Regular Coder

 
Join Date: Oct 2003
Posts: 599
Thanks: 1
Thanked 1 Time in 1 Post
boeing747fp is an unknown quantity at this point
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..
boeing747fp is offline   Reply With Quote
Old 08-01-2006, 09:25 AM   PM User | #3
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,355
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
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.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 08-01-2006, 09:29 AM   PM User | #4
boeing747fp
Regular Coder

 
Join Date: Oct 2003
Posts: 599
Thanks: 1
Thanked 1 Time in 1 Post
boeing747fp is an unknown quantity at this point
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
boeing747fp is offline   Reply With Quote
Old 08-01-2006, 09:30 AM   PM User | #5
cooldaddy
New Coder

 
Join Date: Aug 2005
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
cooldaddy is an unknown quantity at this point
thanks, aint getting the errormessage anymore and the browser name is displaye, however the div aint displayed
cooldaddy is offline   Reply With Quote
Old 08-01-2006, 09:36 AM   PM User | #6
boeing747fp
Regular Coder

 
Join Date: Oct 2003
Posts: 599
Thanks: 1
Thanked 1 Time in 1 Post
boeing747fp is an unknown quantity at this point
it worked for me
boeing747fp is offline   Reply With Quote
Old 08-01-2006, 09:51 AM   PM User | #7
cooldaddy
New Coder

 
Join Date: Aug 2005
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
cooldaddy is an unknown quantity at this point
seems to work indeed thank you very much
cooldaddy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:13 AM.


Advertisement
Log in to turn off these ads.