By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,689 Members | 1,915 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,689 IT Pros & Developers. It's quick & easy.

I want to display the result of a javascript function within html underline tag.

P: 5
Hi,
I am a beginner with javascript.Please help me clarify how to display the result of a javascript function within html underline tag.PFA the code.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.  
  5. <script type="text/javascript">
  6.  
  7. function whichBrs() {
  8. var agt=navigator.userAgent.toLowerCase();
  9. if (agt.indexOf("opera") != -1) return 'Opera';
  10. if (agt.indexOf("staroffice") != -1) return 'Star Office';
  11. if (agt.indexOf("webtv") != -1) return 'WebTV';
  12. if (agt.indexOf("beonex") != -1) return 'Beonex';
  13. if (agt.indexOf("chimera") != -1) return 'Chimera';
  14. if (agt.indexOf("netpositive") != -1) return 'NetPositive';
  15. if (agt.indexOf("phoenix") != -1) return 'Phoenix';
  16. if (agt.indexOf("firefox") != -1) return 'Firefox';
  17. if (agt.indexOf("safari") != -1) return 'Safari';
  18. if (agt.indexOf("skipstone") != -1) return 'SkipStone';
  19. if (agt.indexOf("msie") != -1) return 'Internet Explorer';
  20. if (agt.indexOf("netscape") != -1) return 'Netscape';
  21. if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
  22. if (agt.indexOf('\/') != -1) {
  23. if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
  24. return navigator.userAgent.substr(0,agt.indexOf('\/'));}
  25. else return 'Netscape';} else if (agt.indexOf(' ') != -1)
  26. return navigator.userAgent.substr(0,agt.indexOf(' '));
  27. else return navigator.userAgent;
  28. }
  29.  
  30.  
  31.  
  32. </script>
  33. </head>
  34.  
  35. <body>
  36. Your browser name is <u onload="whichBrs()"></u>
  37. </body>
  38.  
  39. </body>
  40. </html>
  41.  
  42.  
Attached Files
File Type: txt BrowserDetectJavaScriptCode.txt (1.2 KB, 395 views)
Apr 5 '11 #1

✓ answered by Romulo NF

Greetings,

In fact there are lots of ways you can acomplish such thing, here are some examples:

Expand|Select|Wrap|Line Numbers
  1. Your browser name is <u><script type="text/javascript">document.write(whichBrs());</script></u>
  2.  
Or you can do something like:

Expand|Select|Wrap|Line Numbers
  1. Your browser name is <u id="yourBrowser"></u>
  2.  
  3. <script>
  4. var myVar = document.getElementById("yourBrowser"),
  5.     textNode = document.createTextNode(whichBrs());
  6.  
  7. myVar.appendChild(textNode);
  8. </script>
  9.  
Or even:

Expand|Select|Wrap|Line Numbers
  1. Your browser name is <u id="yourBrowser"></u>
  2.  
  3. <script>
  4. var myVar = document.getElementById("yourBrowser");
  5.  
  6. myVar.innerHTML = whichBrs();
  7. </script>
  8.  
Regards,
Romulo

Share this Question
Share on Google+
2 Replies


P: 54
Greetings,

In fact there are lots of ways you can acomplish such thing, here are some examples:

Expand|Select|Wrap|Line Numbers
  1. Your browser name is <u><script type="text/javascript">document.write(whichBrs());</script></u>
  2.  
Or you can do something like:

Expand|Select|Wrap|Line Numbers
  1. Your browser name is <u id="yourBrowser"></u>
  2.  
  3. <script>
  4. var myVar = document.getElementById("yourBrowser"),
  5.     textNode = document.createTextNode(whichBrs());
  6.  
  7. myVar.appendChild(textNode);
  8. </script>
  9.  
Or even:

Expand|Select|Wrap|Line Numbers
  1. Your browser name is <u id="yourBrowser"></u>
  2.  
  3. <script>
  4. var myVar = document.getElementById("yourBrowser");
  5.  
  6. myVar.innerHTML = whichBrs();
  7. </script>
  8.  
Regards,
Romulo
Apr 5 '11 #2

P: 5
Thanks romulo.

actually i already fixed the issue with third solution .Thanks for the additional information.
Apr 6 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.