473,320 Members | 2,092 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.

Get JavaScript output in HTML text

1
Hi,
How To Get Java Script Output In Html Text . I Need Full Coding For That Thank You ,
Oct 24 '07 #1
2 4797
acoder
16,027 Expert Mod 8TB
Hi elahi, welcome to TSDN!

I've changed the thread title. Please use a good thread title.

Can you show an example of what you mean? Do you want to show the JavaScript source code on the web page?
Oct 24 '07 #2
RMWChaos
137 100+
elahi,

You can use this code. It's a cross-browser version, but I am having trouble getting it to work in Netscape 9. If it works there for you, please let me know (it should work as far as I can tell...)

load your files with this code: loadData(../pathName/fileName.txt). It will work with .txt, .xml., and .js files.

Expand|Select|Wrap|Line Numbers
  1. <!--
  2.  
  3. /* **** XMLHttpRequest by RMWChaos **** */
  4. /* **** Cross-Browser Multi-Format v2.0 **** */
  5.  
  6. /* **** Begin: XHR Functions **** */
  7.  
  8.  
  9. var xmlhttp;
  10.  
  11. var fileType;
  12.  
  13.  
  14. function loadData(url)
  15.  
  16.     {
  17.  
  18.     xmlhttp = null;
  19.  
  20.     fileType = url;
  21.  
  22.     /* **** Code for native XHR **** */
  23.  
  24.     if (window.XMLHttpRequest)
  25.  
  26.         {
  27.  
  28.         xmlhttp = new XMLHttpRequest();
  29.  
  30.         }
  31.  
  32.     /* **** Code for MSIE 6.0+ XHR **** */
  33.  
  34.     else if (window.ActiveXObject("Msxml2.XMLHTTP"))
  35.  
  36.         {
  37.  
  38.         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  39.  
  40.         }
  41.  
  42.     /* **** Code for MSIE 5.5+ XHR **** */
  43.  
  44.     else if (window.ActiveXObject("Microsoft.XMLHTTP"))
  45.  
  46.         {
  47.  
  48.         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  49.  
  50.         };
  51.  
  52.     if (xmlhttp != null)
  53.  
  54.         {
  55.  
  56.         xmlhttp.open("GET", url, false);
  57.  
  58.         xmlhttp.onreadystatechange = processData;
  59.  
  60.         xmlhttp.send(null);
  61.  
  62.         }
  63.  
  64.     else
  65.  
  66.         {
  67.  
  68.         alert("We're sorry, but your browser version does not support XMLHTTP / AJAX.");
  69.  
  70.         };
  71.  
  72.     };
  73.  
  74. function processData()
  75.  
  76.     {
  77.  
  78.     /* **** If xmlhttp shows "loaded" **** */
  79.  
  80.     if (xmlhttp.readyState == 4)
  81.  
  82.         {
  83.  
  84.         /* **** If status is "OK" **** */
  85.  
  86.         if (xmlhttp.status == 200)
  87.  
  88.             {
  89.  
  90.             var responseText = xmlhttp.responseText;
  91.  
  92.             var responseXML = xmlhttp.responseXML;
  93.  
  94.             /* **** If target is a text document **** */
  95.  
  96.             if (fileType.lastIndexOf("txt") > -1)
  97.  
  98.                 {
  99.  
  100.                 document.getElementById('content').innerHTML = responseText;
  101.  
  102.                 };
  103.  
  104.             /* **** If target is a xml document **** */
  105.  
  106.             if (fileType.lastIndexOf("xml") > -1)
  107.  
  108.                 {
  109.  
  110.                 // xml parse code here for responseXML
  111.  
  112.                 };
  113.  
  114.             /* **** If target is a javascript file **** */
  115.  
  116.             if (fileType.lastIndexOf("js") > -1)
  117.  
  118.                 {
  119.  
  120.                 /* **** If MSIE **** */
  121.  
  122.                 if (window.execScript)
  123.  
  124.                     {
  125.  
  126.                     execScript(responseText, "javascript");
  127.  
  128.                     return null;
  129.  
  130.                     }
  131.  
  132.                 /* **** If Mozilla, FireFox, Netscape, etc. **** */
  133.  
  134.                 else if (window.eval)
  135.  
  136.                     {
  137.  
  138.                     setTimeout(eval(responseText), 0);
  139.  
  140.                     }
  141.  
  142.                 /* **** If Safari or other **** */
  143.  
  144.                 else
  145.  
  146.                     {
  147.  
  148.                     setTimeout(responseText, 0);
  149.  
  150.                     };
  151.  
  152.                 };
  153.  
  154.             }
  155.  
  156.         else
  157.  
  158.             {
  159.  
  160.             alert("Problem retrieving data:\n" + xmlhttp.status + "\n" + xmlhttp.statusText);
  161.  
  162.             };
  163.  
  164.         };
  165.  
  166.     };
  167.  
  168.  
  169. /* **** End: XHR Functions **** */
  170.  
  171. //-->
  172.  
Oct 25 '07 #3

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

Similar topics

2
by: Dennis M. Marks | last post by:
I create most of my javascripts by modifying others, therefore, I do not have a vast knowledge of it and my question may seem trivial but please help me. If you go to my page...
1
by: Sergio del Amo | last post by:
Hi, I post here because, i think that my problem can happen to a lot of people using javascript with xml and xsl and the future feedback can be useful to all of us. I hava an xml file with a...
15
by: Davide R. | last post by:
Ciao a tutti, vi spiego il mio problema Ho una pagina HTML che referenzia un CSS esterno. Ho alcuni elementi HTML che appartengolo ad una classe (chiamiamola "class1"). Avrei la necessità,...
3
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
1
pbmods
by: pbmods | last post by:
Looking for a print_r() for JavaScript? Look no further! Finally, a decent way to figure out what's in that mysterious Array or Object! Note that this version of print_r() relies on (included)...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
1
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: 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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.