open a new window with javascript element inside it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amzul
    New Member
    • Oct 2007
    • 130

    open a new window with javascript element inside it

    hello all, (congratulation s for the new name admins)

    i have this anoyying issue that i cant resolve.. :(

    i am trying to open a small window (popup) with javascript.

    all i want in that window is an output of a javascript i have.


    here is the function:
    [CODE=javascript]function previewHtmlT(){
    text = "for now i am putting text string but the real thing is <script type javascript></scrip> witch is working cuz i can alert it or document.write it to the new window"
    w=window.open(' ','nevermind',' width=400,heigh t=400,scrollbar s=no,toolbar=no ,directories=no ,status=no,resi zable=yes');
    w.document.open ();
    Body = w.document.getE lementsByTagNam e('body')[0];
    Body.innerHTML= text;
    w.document.clos e();
    }[/CODE]

    why its not working??
    i am getting error saying : 'Body has no properties'

    what am i missing?
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    just remove line 4 and 7 ...

    kind regards

    Comment

    • Amzul
      New Member
      • Oct 2007
      • 130

      #3
      Originally posted by gits
      just remove line 4 and 7 ...

      kind regards
      thanks man BUT :((((

      this only print out the <script></script>
      i want it to execute it

      text = <script type="text/javascript"> document.write( "somthig")</script>

      its not realy document.write( ) but i hope u understand what i am trying to do.

      now its opening a new window and all u can see in it is this (ff):
      <script type="text/javascript"> document.write( "somthig")</script>
      with IE/maxthon u dont see a thing

      i never been so frustrated like i am now

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        a simple way is the following example:

        [CODE=javascript]var js = "alert('test'); ";
        var w = window.open('', 'nevermind', 'width=400,heig ht=400');
        w.eval(js);[/CODE]
        kind regards

        Comment

        • Amzul
          New Member
          • Oct 2007
          • 130

          #5
          Originally posted by gits
          a simple way is the following example:

          [CODE=javascript]var js = "alert('test'); ";
          var w = window.open('', 'nevermind', 'width=400,heig ht=400');
          w.eval(js);[/CODE]
          kind regards
          sorry for the late response.

          yes you are right but this is not what i am trying to do.
          my problem is that i am trying to present a link that is dynamicly been generated so my tag looks like that :
          [CODE=javascript]var script ='<script src="mysource\l ink.php?parma=s omething&parmb= somthingelse&pa rmc=number" type="text\java script"></script>';[/CODE]
          so basicly i need to implant this code to the popup window, and i cant mange to do it in any way :(
          somthing like
          [CODE=javascript]w.document.getE lementsByTagNam e('body')[0].innerHTML=scri pt; [/CODE]

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            ... the script has to be evaled since you want to include an external javascript to a loaded document. the script is to be evaled during! load and thus we have to do that explicitly now. you have two possibilities:

            1. just open a page that get the script included serverside
            2. make an ajax-call that's callback evals the responseText of the script when it has the text retrieved

            kind regards

            Comment

            • Amzul
              New Member
              • Oct 2007
              • 130

              #7
              i was breaking my head yestorday about it ....

              i tried to createelement and then append it to body -- no good (Q:js dont support in creating code element? why?)
              i tried with dialogobjcet of javascript but still had a problem with how to insert it to:
              <body>
              <script src=myDailogVal ue type="text/javascript"></script>
              </body>
              at the end it was a nice learning experience but ffs
              to show a link i have to use ajax?? :(
              i fill like php it all now

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Try this:
                [code=javascript]var head = document.getEle mentsByTagName( "head")[0];
                var script = document.create Element('script ');
                script.type = 'text/javascript';
                script.src = // javascript source...
                head.appendChil d(script);[/code]Modify for the popup window.

                Comment

                Working...