Can I display HTML info within JavaScript?

  • 1
  • Question
  • Updated 8 years ago
  • Answered
Hey Yola It's me again! lol,

I was wondering if it is possible to display information enclosed in <!--<P></P>--> tags depending on the browser type using JavaScript and HTML. I've tried using the document.write(...) procedure but it didn't work.
Thanks People!
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
  • in desperate need of caffeine

Posted 8 years ago

  • 1
Photo of Sanja

Sanja, Official Rep

  • 10698 Posts
  • 495 Reply Likes
Hi Callum

Yes.. you can definitely use HTML markup in your site. You can add HTML either through using an HTML widget or through your text toolbar and clicking on the HTML button.

If you could share with us the code you're trying to use, we can see if we can make it work for you.
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
thanks for the quick reply Sanja =)
heres the code, it's a bit long though:
<!--<html>
<head>
<style type="text/css">
.alert {
background: #fff6bf url(resources/excl.png) center no-repeat;
background-position: 15px 50%; /* x-pos y-pos */
text-align: left;
padding: 5px 20px 5px 45px;
border-top: 2px solid #ffd324;
border-bottom: 2px solid #ffd324;
border-right: 2px solid #ffd324;
border-left: 2px solid #ffd324
}
</style>
<script language="javascript" type="text/javascript">
function display_alert()
{
document.write(<p class="alert"> This site looks best in Mozilla Firefox. Get it <a href="http://download.mozilla.org/?product=...> </p>);
}
function write_blank()
{
document.write("");
}
function check()
{
var browser = navigator.appName;
switch(browser) {
case "Microsoft Internet Explorer": display_alert();break;
case "Netscape": display_alert();break;
case "Mozilla Firefox": write_blank();break;
default: display_alert();
}
}

</script>
</head>
<body onload="check()">

</body>
</html>-->
as you can see, there is HTML markup within the JavaScript, I was wondering why that doesn't display?
thanks again
Photo of Sanja

Sanja, Official Rep

  • 10698 Posts
  • 495 Reply Likes
Hi Callum

Thanks for sharing the code. A couple more questions. What is this code for and where did you grab the code from?

From what I can see, it would seem possible to use this code but there may be something missing.
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
Hi,
The code is to display a yellowish box which informs the user that the site looks best in firefox, it should only display if the user isn't using firefox but it doesn't show at all.

The code came from:
http://www.bioneural.net/2006/04/01/c...
it works without the javascript but not with it.
Photo of Sanja

Sanja, Official Rep

  • 10698 Posts
  • 495 Reply Likes
Hi Callum

This code still does not make sense to me. I'm sorry. I was able to make the css work, but the script code was still not working. DId you also get the script code from that same site?

In the meantime, I did find a different alert box that seemed to work well.

http://www.javascriptkit.com/script/s...

I hope that helps.
Photo of Callum

Callum

  • 357 Posts
  • 32 Reply Likes
Hello again,
I wrote the JavaScript myself to show it depending on the browser, thanks for the other alert box, i will try that out.
Thanks