removing script tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Asad Khan

    #1

    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">doX MLFromString()</script>
    <!-- bunch of stuff -->

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

    var body = document.body.i nnerHTML;
    printWin.docume nt.write (body);

    But this copies the script tag above as well, and then tries to call
    that JS function (doXMLFromStrin g). 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!
  • Klaus Johannes Rusch

    #2
    Re: removing script tag

    Asad Khan wrote:
    [color=blue]
    > 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.[/color]

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

    var body = document.body.i nnerHTML;
    // remove script element here
    printWin.docume nt.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.isPrin tWindow = true;

    <script type="text/javascript">if( typeof(window.m yProperty) ==
    'undefined' || !window.isPrint Window) doXMLFromString ()</script>

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

    --
    Klaus Johannes Rusch
    KlausRusch@atme dia.net

    Comment

    • Randy Webb

      #3
      Re: removing script tag

      Asad Khan wrote:
      [color=blue]
      > I have an HTML file that has a call to a Javascript function in it as
      > follows:
      >
      > <!-- bunch of stuff -->
      > <script type="text/javascript">doX MLFromString()</script>
      > <!-- bunch of stuff -->
      >
      > Now I make a copy of this HTML file by creating a new window and writing
      >
      > var body = document.body.i nnerHTML;[/color]

      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.i nnerHTML;
      var newBody = newBody.replace ('offending script statement here','');

      [color=blue]
      > printWin.docume nt.write (body);[/color]

      printWin.docume nt.write(newBod y);
      [color=blue]
      > How can I stop this?[/color]

      Simply replace the strings in the newBody that you don't want duplicated.


      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      Working...