document.write() 在 Fancybox 1 窗口中


document.write() in a Fancybox 1 window

可能我对Fancybox v1有些误解,但有以下小问题。首先,我通过单击链接调用fancybox:

$(document).ready(function() {
  $(".href").click(function() {
    $.fancybox.open({
      href : $(this).attr("data-id"),
      type : 'iframe'
    });
  });
});

这会加载一个简单的带有JS的PHP/HTML页面,以填充到Fancybox窗口中:

<!DOCTYPE html><html><head><title></title></head>
<body>
<?php
# this is the fancybox content 
echo "<script>var dcwrtext = 'random_text'; document.write(dcwrtext);</script> Some other content to show on fancybox.";
?>
</body></html>

内容显示没有问题,但细微差别是,document.write值在结束</script>标记之后回显:这使得内容在页面上可见,而不是document.write()功能。您可以在源代码中看到以下内容:

<body>
<script>var dcwrtext = 'random_text'; document.write(dcwrtext);</script>**random_text** Some other content to show on fancybox.
</body>

问题似乎出在 fancybox 上,如果我在标准 HTML(不是花式框)页面上使用该document.write(),正如预期的那样,它将在页面上正确显示"random_text",仅在<script></script>内部。这是源代码:

<body>
<script>var dcwrtext = 'random_text'; document.write(dcwrtext);</script> Some other content to show on fancybox.
</body>

我需要的是,如果我打开 fancbox 窗口,"random_text"不应该出现在结束</script>标签之后,而只能由 document.write() 函数显示。

这是我的测试方式:

主页:

<html>
<head>
<title></title>
<meta name="" content="">
    <link rel="stylesheet" type="text/css" href="fancybox/source/jquery.fancybox.css?v=2.1.2" media="screen" />
</head>
<body>
<div data-id="fancy.php" class="href">open fancy</div>
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
<script type="text/javascript" src="fancybox/source/jquery.fancybox.js?v=2.1.3"></script>
<script>
$(document).ready(function() {
  $(".fancybox").fancybox();
  $(".href").click(function() {
    $.fancybox.open({
      href : $(this).attr("data-id"),
      type : 'iframe'
    });
  });
});
</script>
<div id="theid" class="fancybox"></div>
</body>
</html>
以及在花式

框中打开的页面:花式.php

<html>
<head>
<title></title>
</head>
<body>
<?php
$randomtext = "random_text";
echo "<script>var dcwrtext = '$randomtext'; document.write(dcwrtext);</script>Some other content to show on fancybox";
?>
</body>
</html>

[我不得不包含jquery-migrate-1.2.1.js,因为错误 [ 未捕获的类型错误:无法读取未定义的属性'msie'] 当使用fancybox包含较新版本的jquery时]