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

javascript generated html

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: 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 discussion thread is closed

Replies have been disabled for this discussion.