tags:

views:

96

answers:

5

Hi guys, I need PHP to open up a new window with a text from a variable.

Here's what I tried.

  echo "<script>   
  $myWin=window.open('','$myWin','menubar,scrollbars,left=30px,top=40px,height=800px,width=800px');
  $myWin.document.write(".$logtext."); 
  </script>";  

but it doesn't work. any better ideas or suggestions? Thanks! :)

+2  A: 

This has nothing to do with PHP: You're outputting a string. That string happens to be JavaScript that happens to be interpreted by the browser. You need to debug that JavaScript.

For example, this line:

$myWin=window.open(...

will result in

 =window.open(...

because $myWin is interpreted as a variable by PHP (unless the $myWin variable was set in PHP - it's not entirely clear from your code whether it is or not, but my guess it is not.)

The solution - unless, as I said myWin is set - would be removing the $ from the variable name to make it a normal JS variable.

Always look at the end result in your browser. And, please please, describe the problem in more detail than "doesn't work"!

Pekka
+1 Well spotted!
Gumbo
+2  A: 

Just guess untill more info from you..

$myWin.document.write('$logtext');
hsz
+1  A: 

If you're trying to do logging, try firePHP: http://www.firephp.org/.

Once installed, you can do it like this, if you don't want to use firephp.

Get FireBug, and try this.

<script>
    console.log("<?=$msg?>");
</script>
Derrick
+1  A: 

I don't know what the PHP string $logtext looks like, but it seems to me that the javascript string wouldn't have the proper syntax.

Try $myWin.document.write(\"$logtext\");

DLH
better yet, pass $logtext through `json_encode()` first, turning it into absolutely legitimate javascript data
Marc B
+1  A: 

First of all $myWin can simply be myWin in JS:

my_window= window.open ('','mywindowname','status=1,width=350,height=150');
my_window.document.write('".$myphpstring."');  
DBQ
so just to clarify, this would be your version: echo "<script> myWin=window.open('','WindowName','menubar=1,scrollbars=1,left=30px,top=40px,height=800px,width=800px'); myWin.document.write('".$logtext."'); </script>";
DBQ
It works OK so for as for opening a new window and showing the $logtext file, but only if it is rather short. When I assign the real value from the database ( long text ), like 50 pages, the new window does not open... is there any limitation in size?
Honestly, not sure. Typically I use a pop up for smaller bits of information. If it really is 50 pages, why not link to a complete content item without a popup? Or if it is a true document why not output to a PDF and display?
DBQ