Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with x.document.write('string');

    Hi everybody,

    I am working with a javascript function for my javascript toolbar. With this function i am trying to find out all the javascript present in the page and preparing a string and trying to write that string in a new window.

    But when i am trying to do this with my function it is not writing all the javascript found in that page. some part is not written in the new window.

    do i need to use any flush or anything for this purpose.....?

    You please have a look of my javascript function below:
    --------------------------------------------------------
    function viewJavascript()
    {
    var tagArray = window.document.getElementsByTagName('*');
    var s ='';
    var js='';
    for(var i=0;i<tagArray.length;i++)
    {
    s = (tagArray[i].tagName).toLowerCase();
    if((s=='script')&&((tagArray[i].language).toLowerCase()=='javascript'))
    {
    js='<br>'+js+tagArray[i].innerHTML;
    }
    }
    var n = window.open('javascript');
    n.document.write(js);
    }
    --------------------------------------------------------

    thanks in advance

    batta

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Let's see if it even got it in the first place.

    js='<br>'+js+tagArray[i].innerHTML;
    alert(js);

    Add that alert in there.
    Does the js variable even have all the script in it?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi
    when i add

    alert(js);

    in js string variable i am able to see all the javascript but the problem is there only.

    that java script also contatins the below things

    ------------------------------
    <!--

    //-->
    -----------------------------

    with in this the java script is coming.

    so in html page the above one is comment. so it is not showing anything

    can you tell me how to remove these things

    thanks
    batta

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Stop putting them in the script.
    They aren't needed any more. They're for browsers from 10 years ago that didn't understand the script element.

    If you want to keep them for some odd reason, you'd need to write some sort of regular expression to parse them out with the string replace function.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •