473,378 Members | 1,354 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,378 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 2489
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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...

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.