...

View Full Version : object required, dunno how to solve



cooldaddy
08-01-2006, 08:59 AM
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>

boeing747fp
08-01-2006, 09:04 AM
you have to set it up as a function and call it on body onLoad="" like this:


<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>

vwphillips
08-01-2006, 09:25 AM
document.write can only be used as page first rendered


<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>

boeing747fp
08-01-2006, 09:29 AM
lol i originally posted that but i was having problems getting it to work myself... and i was just gonna post an update


<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

cooldaddy
08-01-2006, 09:30 AM
thanks, aint getting the errormessage anymore and the browser name is displaye, however the div aint displayed

boeing747fp
08-01-2006, 09:36 AM
it worked for me

cooldaddy
08-01-2006, 09:51 AM
seems to work indeed :) thank you very much



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum