开发者

displaying php content in JavaScript new window

开发者 https://www.devze.com 2023-04-11 19:15 出处:网络
Here is the code that I have so far: $output = <<<BLOCK <html> <head> <title>Preview!</title>

Here is the code that I have so far:

$output = <<<BLOCK

    <html>
        <head>
            <title>Preview!</title>

            <script type="text/javascrit">
                var content = $data;
            </script> 

        </head>
        <body>
            <a href="" onclick="preview()">Click Me!</a>
            <script type="text/javascript"> 
                function preview(){
                    var preview = window.open('','preview','scrollbars=1,height=500,width=500,resizable=1');
                    preview.document.open();
                    preview.document.write(content);
 开发者_运维技巧                   preview.document.close(); 

                }
            </script> 
        </body>
    </html>     
BLOCK;
echo $output;   

$data contains a full html document generated by the php script.

This doesn't seem to work, but I think you can get the idea what I'm trying to do.


Wee have to know what does $data contains, but you certainly have to escape quotes or specials chars ...


"data" is generated from another script...can we see it? UPDATED: You cant pass "content" from the head to the body like that, it is null , try as a given parameter to the function preview. Try accessing it where you do the OPEN().

Or store "data" in a hidden div or get it via AJAX(preferably). content2=null; content="asdsadas";

$data="asdsadas";
$output = "
    <html>
        <head>
            <title>Preview!</title>

            <script type=\"text/javascript\">
                var content2 = '".$data."'
            </script> 

        </head>
        <body>
            <a href=\"\" onclick=\"preview()\">Click Me!</a>
            <script type=\"text/javascript\"> 
                function preview(){
                var content = '".$data."'
                    var preview = window.open('','preview','scrollbars=1,height=500,width=500,resizable=1');
                    preview.document.open();
                    preview.document.write(content);
            preview.document.write(content2);
                    preview.document.close(); 

                }
            </script> 
        </body>
    </html>";
echo $output;  
0

精彩评论

暂无评论...
验证码 换一张
取 消