PDA

View Full Version : javascript - show something on page



omgDAN!
12-04-2007, 04:30 PM
right I have this:


<script>
if(navigator.userAgent.indexOf("Firefox") != -1)
{
alert ("your using firefox")
}
else
{
alert ("your not using firefox")
}
</script>

is there any way I could get it to display some text in a div onto the page instead of an alert?

thanks

Splinter
12-04-2007, 04:33 PM
Yup.. just place this into your body:


<div id="browser"></div>


and change your script to this:


<script>
if(navigator.userAgent.indexOf("Firefox") != -1)
{
document.getElementById("browser").innerHTML = 'Your using firefox!'
}
else
{
document.getElementById("browser").innerHTML = 'Your not using firefox!'
}
</script>

omgDAN!
12-04-2007, 04:40 PM
I get this:
http://www.uploadz.co.uk/505errorjs.png

Splinter
12-04-2007, 04:42 PM
What are you testing it in?? :S Should work in just a html file.. :S

omgDAN!
12-04-2007, 04:44 PM
Frontpage. But when I open it in firefox and IE I just get blank pages.

Splinter
12-04-2007, 04:58 PM
Was the previous script working.. also try:


<script type="text/javascript">
if(navigator.userAgent.indexOf("Firefox") != -1)
{
document.getElementById("browser").innerHTML = 'Your using firefox!'
}
else
{
document.getElementById("browser").innerHTML = 'Your not using firefox!'
}
</script>

Want to hide these adverts? Register an account for free!