Can one divert or hide document.write output?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Wilkins

    #1

    Can one divert or hide document.write output?

    I am using <SCRIPT src=...> to import a Javascript routine from a remote
    source. I am then using some of the variables given values in the
    routine, in my own Javascript..

    Unfortunately the routine also outputs to the page using document.write.
    I don't want this output. Any ideas how I can get rid of it?

    --
    Best wishes,

    Geoff Wilkins
    GeoffW@wordsmit h.demon.co.uk
  • Martin Honnen

    #2
    Re: Can one divert or hide document.write output?



    Geoff Wilkins wrote:
    [color=blue]
    > I am using <SCRIPT src=...> to import a Javascript routine from a remote
    > source. I am then using some of the variables given values in the
    > routine, in my own Javascript..
    >
    > Unfortunately the routine also outputs to the page using document.write.
    > I don't want this output. Any ideas how I can get rid of it?[/color]

    I am not sure you need that as you could take the script from the src
    and rewrite it as necessary but if needed you can disable document.write
    temporarily to a function doing nothing and then restore it later:

    <html>
    <head>
    <title>disablin g document.write</title>
    <script type="text/javascript">
    function disableDocWrite () {
    document.oldDoc umentWrite = document.write;
    document.write = function () {};
    }
    function enableDocumentW rite () {
    document.write = document.oldDoc umentWrite;
    }
    disableDocWrite ();
    </script>
    <script type="text/javascript">
    // this would be the external script to be loaded with
    // script src, to have a complete example I have simply used
    // an embedded script here
    function getGOD () {
    var GOD = 'Kibo';
    document.write( 'All praise ' + GOD + '.');
    return GOD;
    }
    </script>
    <script type="text/javascript">
    var GOD = getGOD();
    alert(GOD);
    enableDocumentW rite();
    </script>
    </head>
    <body>
    <h1>document.wr ite test</h1>
    <p>
    <script type="text/javascript">
    document.write( 'Kibology for all.');
    </script>
    </p>
    </body>
    </html>
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Geoff Wilkins

      #3
      Re: Can one divert or hide document.write output?

      In message <404872ea$1@ola f.komtel.net>, Martin Honnen
      <mahotrash@yaho o.de> writes[color=blue]
      >Geoff Wilkins wrote:
      >[color=green]
      >> I am using <SCRIPT src=...> to import a Javascript routine from a
      >>remote source. I am then using some of the variables given values in
      >>the routine, in my own Javascript..
      >> Unfortunately the routine also outputs to the page using
      >>document.writ e. I don't want this output. Any ideas how I can get rid
      >>it?[/color]
      >
      >I am not sure you need that as you could take the script from the src
      >and rewrite it as necessary[/color]

      The problem is that I want the values assigned to the variables at the
      remote location
      [color=blue]
      >but if needed you can disable document.write temporarily to a function
      >doing nothing and then restore it later:[/color]

      Great - this is just what I wanted. I thought that there must be some
      way of doing it. Many thanks.
      [color=blue]
      >
      ><html>
      ><head>
      ><title>disabli ng document.write</title>
      ><script type="text/javascript">
      >function disableDocWrite () {
      > document.oldDoc umentWrite = document.write;
      > document.write = function () {};
      >}
      >function enableDocumentW rite () {
      > document.write = document.oldDoc umentWrite;
      >}
      >disableDocWrit e();
      ></script>
      ><script type="text/javascript">
      >// this would be the external script to be loaded with
      >// script src, to have a complete example I have simply used
      >// an embedded script here
      >function getGOD () {
      > var GOD = 'Kibo';
      > document.write( 'All praise ' + GOD + '.');
      > return GOD;
      >}
      ></script>
      ><script type="text/javascript">
      >var GOD = getGOD();
      >alert(GOD);
      >enableDocument Write();
      ></script>
      ></head>
      ><body>
      ><h1>document.w rite test</h1>
      ><p>
      ><script type="text/javascript">
      >document.write ('Kibology for all.');
      ></script>
      ></p>
      ></body>
      ></html>[/color]

      Comment

      Working...