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;
精彩评论