简体   繁体   English

在JavaScript新窗口中显示php内容

[英]displaying php content in JavaScript new window

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. $ data包含由php脚本生成的完整html文档。

This doesn't seem to work, but I think you can get the idea what I'm trying to do. 这似乎不起作用,但是我认为您可以了解我正在尝试做的事情。

"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. 更新:您不能像这样将“内容”从头部传递到身体 ,它为null ,请尝试将其作为给定参数传递给功能预览。 Try accessing it where you do the OPEN(). 尝试在执行OPEN()的位置访问它。

Or store "data" in a hidden div or get it via AJAX(preferably). 或将“数据”存储在隐藏的div中,或通过AJAX(最好)获取。 content2=null; content2 = null; content="asdsadas"; 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;  

Wee必须知道$ data包含什么,但是您当然必须转义引号或特殊字符...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM