473,385 Members | 1,610 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,385 software developers and data experts.

javascript generated html

Suppose I download a html file with javascript in it, for example,

<html>
<body>
<script language="JavaScript">
document.write("Hello");
</script>
</body>
</html>

How can I translate that to pure html,

<html>
<body>
Hello
</body>
</html>

I am looking for a c++ solution.

Thanks,

qk
Jul 20 '05 #1
9 2694
qu******@yahoo.com (qu******@yahoo.com) writes:
Suppose I download a html file with javascript in it, for example, .... <script language="JavaScript">
document.write("Hello");
</script> .... How can I translate that to pure html, .... Hello

....

In this, simple, case it is fairly easy. Remove the script tags and
change calls to document.write into its value. But that only works when
all the script element contains are calls to document.write.

If the Javascript is more complicated, you will have to execute it to
know what it does. The simplest solution would be to load a browser
and put the page into it, and then extract the generated HTML.
Otherwise, you will need an implementation of Javscript and a runtime
environment similar ot that provided by a browser in order to execute
the code correctly.

If you are aiming for the Windows platform, You can probably remotely
control IE, or make an instance of the HTML rendering widget, and put
the code into it. When (or if) it finishes parsing the page, including
the embedded Javascript, you can use
document.documentElement.innerHTML to get the contents of the
resulting page's html element.

If you are using this for anything critical, and the user supplies the
page, then they can make pages where the Javascript never finishes
executing. A simple "while(true){}" can do it, but you can check in
advance whether a script will loop forever or not, it can always be
disguised to fool your check. You will have to time-out the browser
if it runs for too long.

You will also be open to any security bugs in IE.
<URL:http://www.pivx.com/larholm/unpatched/>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
In article <ea**************************@posting.google.com >,
qu******@yahoo.com says...
Suppose I download a html file with javascript in it, for example,

<html>
<body>
<script language="JavaScript">
document.write("Hello");
</script>
</body>
</html>

How can I translate that to pure html,


In any more than a trivial case like this, you can't -- the primary
reason people use Javascript in the first place is to do things that are
impossible or thoroughly unreasonable using HTML.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 20 '05 #3
DU
qu******@yahoo.com wrote:
Suppose I download a html file with javascript in it, for example,

<html>
<body>
<script language="JavaScript">
document.write("Hello");
</script>
</body>
</html>

How can I translate that to pure html,

<html>
<body>
Hello
</body>
</html>

I am looking for a c++ solution.

Thanks,

qk


IMO, your question with your specific example is easy to answer: just
remove the script tags. But the answer to the general question is it is
impossible as there are many many ways (DOM methods, even DOM
attributes) to dynamically add (and/or insert and/or append, modify,
move, split, etc.. even import) new elements (and/or new text node
values) into an html file. Adding new DOM nodes with display:none or
visibility:hidden or opacity to 0 or etc... (dynamically settable later)
would still have to be considered as cases to consider.

Your question is a very valid one though as W3C thinks people are
resorting to (and/or over-using, mis-using, abusing) DHTML/javascript
way too often when simple, normal HTML would suffice.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #4
Ivo
qu******@yahoo.com (qu******@yahoo.com) wrote in message news:<ea**************************@posting.google. com>...
Suppose I download a html file with javascript in it, for example,

<html>
<body>
<script language="JavaScript">
document.write("Hello");
</script>
</body>
</html>

How can I translate that to pure html,
I am looking for a c++ solution.
Thanks,
qk

You need a very clever script that interprets the javascript, because
it has to know in advance what is going to be asked of the javascript.
Onclicks, onchanges and all other events will have to be assumed. In
other words, I don't think it 's really possible.

Why was it written in javascript in the first place??

If you know that the javascript doesn't change much, but it is still
too much work to convert all your pages by hand, perhaps you could run
them as they are, and even add a little javascript that submits the
generated source back to the server once it has finished generating,
where you can replace the page with the received html code.
HTH
Ivo
Jul 20 '05 #5
How does the browser understand javascript? Does the browser transfer
it into html (if it is something like document.write) first?

Thanks,
sa*****@mail.com (Ivo) wrote in message news:<80**************************@posting.google. com>...
qu******@yahoo.com (qu******@yahoo.com) wrote in message news:<ea**************************@posting.google. com>...
Suppose I download a html file with javascript in it, for example,

<html>
<body>
<script language="JavaScript">
document.write("Hello");
</script>
</body>
</html>

How can I translate that to pure html,
I am looking for a c++ solution.
Thanks,
qk

You need a very clever script that interprets the javascript, because
it has to know in advance what is going to be asked of the javascript.
Onclicks, onchanges and all other events will have to be assumed. In
other words, I don't think it 's really possible.

Why was it written in javascript in the first place??

If you know that the javascript doesn't change much, but it is still
too much work to convert all your pages by hand, perhaps you could run
them as they are, and even add a little javascript that submits the
generated source back to the server once it has finished generating,
where you can replace the page with the received html code.
HTH
Ivo

Jul 20 '05 #6
In article <ea**************************@posting.google.com >,
qu******@yahoo.com says...
How does the browser understand javascript? Does the browser transfer
it into html (if it is something like document.write) first?


No -- the browser has a Javascript interpreter (or invokes a separate
one) that understands Javascript. HTML has only the VERY most limited
involvement -- one of the two (usually the browser, I'd guess) has to
recognize the bit of HTML that marks the end of the Javascript, so
things switch back to normal HTML mode at the end. What the Javascript
produces does NOT (in any case of which I'm aware at any rate) get
converted to HTML to be displayed or anything like that though.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 20 '05 #7
JRS: In article <MP************************@news.clspco.adelphia.n et>,
seen in news:comp.lang.javascript, Jerry Coffin <jc*****@taeus.com>
posted at Sun, 21 Sep 2003 01:15:12 :-
In article <ea**************************@posting.google.com >,
qu******@yahoo.com says...
How does the browser understand javascript? Does the browser transfer
it into html (if it is something like document.write) first?


No -- the browser has a Javascript interpreter (or invokes a separate
one) that understands Javascript. HTML has only the VERY most limited
involvement -- one of the two (usually the browser, I'd guess) has to
recognize the bit of HTML that marks the end of the Javascript, so
things switch back to normal HTML mode at the end. What the Javascript
produces does NOT (in any case of which I'm aware at any rate) get
converted to HTML to be displayed or anything like that though.


That which is written by document.write, and that which is written by
DynWrite (FAQ 4.15), is treated as HTML. For example, <br> does not
make four marks on the page, but causes the insertion point to move to a
new line.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #8
Microsoft's IHtmlDocument(a COM object) can parser html with
javascript. For example, if there is
var msg1 = "<a href = a.html>link</a>"
document.write(msg1)
in the file, IHtmlDocument can extract the link, just as a link in
html. Thus, IHtmlDocument must have a Javascript interpreter in it,
right? I am looking for such a Javascript interpreter which can be put
in c++ app.

Thanks,

qk


Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in message news:<xZ**************@merlyn.demon.co.uk>...
JRS: In article <MP************************@news.clspco.adelphia.n et>,
seen in news:comp.lang.javascript, Jerry Coffin <jc*****@taeus.com>
posted at Sun, 21 Sep 2003 01:15:12 :-
In article <ea**************************@posting.google.com >,
qu******@yahoo.com says...
How does the browser understand javascript? Does the browser transfer
it into html (if it is something like document.write) first?


No -- the browser has a Javascript interpreter (or invokes a separate
one) that understands Javascript. HTML has only the VERY most limited
involvement -- one of the two (usually the browser, I'd guess) has to
recognize the bit of HTML that marks the end of the Javascript, so
things switch back to normal HTML mode at the end. What the Javascript
produces does NOT (in any case of which I'm aware at any rate) get
converted to HTML to be displayed or anything like that though.


That which is written by document.write, and that which is written by
DynWrite (FAQ 4.15), is treated as HTML. For example, <br> does not
make four marks on the page, but causes the insertion point to move to a
new line.

Jul 20 '05 #9
Roland
3
Hello, you can see generated javascript source with the tracer tool

http://www.netamo.com/tracer

It processes the page as the browser does, and traces every function. Check it. We are developing it and it's still beta, so we appreciate feedback. Thanks
May 12 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Web Spinner | last post by:
I am running Windows 2000 and I can't seem to get my JavaScript working with ASP. I placed my HTML code in a file called x.asp under c:\Inetpub\wwwroot, and I placed my JavaScript code in a file...
3
by: Liza | last post by:
dear all, does a client side script always need a server side script in order to function? how can i get my javascript application to send the details of a user filled form to me without...
6
by: KKramsch | last post by:
OK, here's the scenario: I have a CGI script that generates a page with frames (BTW, I'm not crazy about frames, but in this case the decision to use them is out of my hands). In a typical...
0
by: Jim Corey | last post by:
I'm experimenting with a code generator that creates an html page which includes a lot of javascript that modifies (for example) input boxes on the page. I can paste the html into an aspx page,...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
14
by: Rich | last post by:
I am converting my enterprise solution from VS 2003 (.NET v1.1.4322) to VS 2005 (.NET v2.0.50727). The entire solution uses serveral technologies - Windows Server 2003 (AD, SQL Server 2000, IIS,...
3
by: Nathan Gilbert | last post by:
I am wanting to use javascript to select between different *.css files dependent on the user's browser. I am also wanting to generate the html document containing this javascript dynamically using...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
2
by: HopfZ | last post by:
Server sends cookie to browser and the browser send the same cookie back to the server according to Wikipedia. Do browsers send even javascript-generated cookie to servers? For example, if I...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.