473,396 Members | 2,030 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,396 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 2491
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Ley | last post by:
Hi, IE has the ability to setExpressions on stylesheets so you can calculate the value of the css property through script. For various reasons I'm wanting to use a side-effect of this to...
11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
2
by: Raja Kannan | last post by:
Is there a way to remove text portion from the HTML keeping the HTML Tags using the browser, say javascript RegEx or something ? I have seen lot of examples removing HTML tags to get the text...
16
by: graham.reeds | last post by:
I am updating a website that uses a countdown script embedded on the page. When the page is served the var's are set to how long the countdown has left in minutes and seconds, but the rest of the...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
2
by: Daz | last post by:
Hi everyone. I would like to know if it's possible to clean up my scripts, or if you will, 'make them biodegradable'. Some of my smaller script will be download to the users browser, but I would...
2
by: Daz | last post by:
Hi everyone. Is it possible to remove a script that has been added to a page? I have asked this question before, and was told that it was pretty much impossible to do, unless of course, I...
2
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */...
6
by: lilly07 | last post by:
Hi I tried a simple script to remove the directory as below: #!/usr/bin/perl -w use File::Find; #finddepth(sub{rmdir},'.') system('rm -rf test3'); 1. finddepth(sub{rmdir},'.') removed all...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.