471,595 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

removing script tag


I have an HTML file that has a call to a Javascript function in it as
follows:

<!-- bunch of stuff -->
<script type="text/javascript">doXMLFromString()</script>
<!-- bunch of stuff -->

Now I make a copy of this HTML file by creating a new window and writing

var body = document.body.innerHTML;
printWin.document.write (body);

But this copies the script tag above as well, and then tries to call
that JS function (doXMLFromString). I don't want it to do that.

In other words I dont want that javascript statement to be executed. I
tried removing it from the document (using removechild) however it would
still get called.

How can I stop this?
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
2 2418
Asad Khan wrote:
In other words I dont want that javascript statement to be executed. I
tried removing it from the document (using removechild) however it would
still get called.


You need to remove the script element before writing out the new window,
that is

var body = document.body.innerHTML;
// remove script element here
printWin.document.write(body);

Alternatively you could set a window property and query that property to
suppress execution of the code in secondary windows, for example

printWin.isPrintWindow = true;

<script type="text/javascript">if(typeof(window.myProperty) ==
'undefined' || !window.isPrintWindow) doXMLFromString()</script>

or control the execution of the script based on the page address.

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 23 '05 #2
Asad Khan wrote:
I have an HTML file that has a call to a Javascript function in it as
follows:

<!-- bunch of stuff -->
<script type="text/javascript">doXMLFromString()</script>
<!-- bunch of stuff -->

Now I make a copy of this HTML file by creating a new window and writing

var body = document.body.innerHTML;
body isn't a very good variable name. Does the second body refer to the
body of the page, or, to the variable body you just created?
var newBody = document.body.innerHTML;
var newBody = newBody.replace('offending script statement here','');

printWin.document.write (body);
printWin.document.write(newBody);
How can I stop this?


Simply replace the strings in the newBody that you don't want duplicated.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jim Ley | last post: by
2 posts views Thread by Raja Kannan | last post: by
16 posts views Thread by graham.reeds | last post: by
24 posts views Thread by RyanTaylor | last post: by
2 posts views Thread by Daz | last post: by
2 posts views Thread by Daz | last post: by
reply views Thread by leo001 | last post: by

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.