473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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

2 11638
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
Thanks romulo.

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

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

Similar topics

1
by: Markusek Peter | last post by:
How can I call JavaScript function within <TABLE> tags. I've got <table width="here should be return value from js script"> Thank you.
2
by: hemant | last post by:
hi all, i am working on a website using asp.net-vb.net i am using a textbox(web control) and want to run javascript function as the text in the textbox is changed. but as soon as i run the page...
3
by: MicroMoth | last post by:
Hi, I'm trying to call a Javascript function within a foreach loop. I am loop over a series of users and I want to call the JS function which opens a new window, passing in the user id to each...
1
by: supin | last post by:
hi, i work in asp.net2.0/c#.not much expert in javascript.i have a variable declared in the c# code behind page.assume the variable contains some value. i have a javascript function in the...
4
by: sajithkahawatta | last post by:
i want to call a java script function from code behind. in page1.aspx page i placed script' <script language="javascript"> function SetSelected() { infoTextBox.select(); } </script>
10
by: patelxxx | last post by:
Problem: I am trying to input my name in a text box and I click on transfer and I want the name to appear on the same page (i.e. in another form). How is this done? <BODY> <HTML> <form...
2
by: gsherp | last post by:
Is there anyway to call a javascript function within an innerHTML call? example: var someelement = document.createElement("input"); var someelement2 = document.createElement("input"); ...
5
by: gubbachchi | last post by:
Hi all, How to pass the php date variable to javascript function. Here is the code I have tried out, but this is not recovering the date correctly in the javascript function <html> <script...
7
Daxthecon
by: Daxthecon | last post by:
What I need. -When there is nothing in the cell it needs to be red -When there is something in the cell it should be green -There should be a search input and it should bring up(on the next page...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.