By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

open a new window with javascript element inside it

100+
P: 130
hello all, (congratulations 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:
Expand|Select|Wrap|Line Numbers
  1. function previewHtmlT(){
  2.     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"
  3.     w=window.open('','nevermind','width=400,height=400,scrollbars=no,toolbar=no,directories=no,status=no,resizable=yes');
  4.     w.document.open();
  5.     Body = w.document.getElementsByTagName('body')[0]; 
  6.     Body.innerHTML=text;
  7.      w.document.close();
  8. }
why its not working??
i am getting error saying : 'Body has no properties'

what am i missing?
Apr 8 '08 #1
Share this Question
Share on Google+
7 Replies


gits
Expert Mod 5K+
P: 5,390
just remove line 4 and 7 ...

kind regards
Apr 8 '08 #2

100+
P: 130
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
Apr 8 '08 #3

gits
Expert Mod 5K+
P: 5,390
a simple way is the following example:

Expand|Select|Wrap|Line Numbers
  1. var js = "alert('test');";
  2. var w = window.open('', 'nevermind', 'width=400,height=400');
  3. w.eval(js);
kind regards
Apr 8 '08 #4

100+
P: 130
a simple way is the following example:

Expand|Select|Wrap|Line Numbers
  1. var js = "alert('test');";
  2. var w = window.open('', 'nevermind', 'width=400,height=400');
  3. w.eval(js);
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 :
Expand|Select|Wrap|Line Numbers
  1. var script ='<script src="mysource\link.php?parma=something&parmb=somthingelse&parmc=number" type="text\javascript"></script>';
so basicly i need to implant this code to the popup window, and i cant mange to do it in any way :(
somthing like
Expand|Select|Wrap|Line Numbers
  1. w.document.getElementsByTagName('body')[0].innerHTML=script; 
Apr 9 '08 #5

gits
Expert Mod 5K+
P: 5,390
... 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
Apr 9 '08 #6

100+
P: 130
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=myDailogValue 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
Apr 9 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Try this:
Expand|Select|Wrap|Line Numbers
  1. var head = document.getElementsByTagName("head")[0];
  2. var script = document.createElement('script');
  3. script.type = 'text/javascript';
  4. script.src = // javascript source...
  5. head.appendChild(script);
Modify for the popup window.
Apr 9 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.