您所看到的JavaScript是一个PHP脚本服务器。使用一些浏览器/网络调试器工具来检查HTTP响应:
HTTP/1.1 200 OK
Server nginx/0.7.67
Date Wed, 06 Jun 2012 11:50:44 GMT
Content-Type text/html
Connection keep-alive
X-Powered-By PHP/5.3.10
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Content-Encoding gzip
并且看到它是由PHP驱动的。所以它是PHP脚本的输出,而不是常规的JavaScript文档。
当省略frame=1
时,PHP脚本输出JavScript。 当包含frame=1
时,它会通知PHP脚本将JavaScript嵌入到HTML页面中并将其提供。
更新: PHP脚本可以这个样子:
<?php
$asHTML = $_GET['frame'] == 1;
if($asHTML) {
// Generate HTTP headers for HTML, like
header("Content-Type", "text/html");
} else {
// Generate HTTP headers for the JavaScript, like
header("Content-Type", "text/javascript");
}
if($asHTML) {
// Generate HTML top document part
echo "<html><head><title>Title</title></head><body><script type=\"text/javascript\">";
// Other HTML header stuff here as well, see the live example (as I am too lazy to type it here)
}
// Read the JavaScript from a file that is available on the server
readfile("javascript.js");
if($asHTML) {
// Close HTML tags
echo "</script></body></html>";
}
注意,我很快就打字了一起,所以它可能是完全错误的。但它应该给你一个总的想法。
难道你不能在这里粘贴代码 – 2012-06-06 11:38:21
了解更多javascript ... –
使用JavaScript无法显示HTML吗? JavaScript的主要用途之一是操作DOM - 即显示HTML。从JavaScript和DOM操作的基本指南开始。 –