有人能告诉我为什么这个脚本不能运行吗?
Can someone tell me why this script doesn't run?
当我打开这个页面没有任何反应。那么这段代码的错误是什么呢?
这是代码:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function code(){
var filename = loc.pathname.split("/");
filename = filename[pathname.length-1];
alert(filename);
<iframe src="http://url/" +currentPageUrl scrolling="yes" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;">
Your browser doesn't support IFrames
</iframe>`
}
</script>
<title>Index</title>
</head>
<body onload="code();">
</body>
</html>
我不知道你想做什么,但是你的代码中有很多错误。
loc
应为location
我猜你在做类似的事情。
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function code() {
var filename = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
document.body.innerHTML = "<iframe src=" + filename + " scrolling='yes' style='position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;'>your browser doesn't support iframe<iframe>";
}
</script>
<title>Index</title>
</head>
<body onload="code();">
</body>
</html>
因为你没有一个有效的脚本。
- loc未定义
- 你只是有一个iFrame标签飞来飞去的JS代码。
这段代码有几个问题:
-
loc
看起来没有定义。也许你想要location
-
要向DOM添加代码,可以使用:
document.body.innerHTML = "<iframe src='http://' + variable ></iframe>"
-
确保所有其他变量都已定义。例如,在获取长度时使用
location.pathname
。
相关文章:
- Cufon脚本没有'不能在IE9下工作
- 我的代码在<脚本>标记,但没有'不能在外部文件中工作
- JQuery脚本没有'Don’我不能工作两次
- "npm运行构建:css"不能工作,而当我自己运行脚本时是可以的
- 为什么我的JavaScript / JSON脚本不能在Internet Explorer中工作
- 为什么这个ajax脚本不能在wamplocalhost上工作
- History.js没有'不能在内容脚本中工作
- 从Java脚本返回多个值,这些值不能在firefox上运行(在IE上运行良好)
- 谷歌应用程序脚本可以作为Web应用程序,但不能作为电子表格脚本
- 可以'我的单词随机化器脚本不能正常循环
- 不能在内容脚本中使用 jQuery ajaxComplete
- 打字脚本:参数类型函数不能分配给参数类型函数
- 为什么jQuery脚本在jFiddle上工作,但不能在我的本地机器上工作
- java脚本不能自动写入硬盘,但Java可以这样做
- 不能在 AppFog Node App 上包含脚本/css
- jQuery:为什么我的脚本不能删除类
- 为什么 AngularJS 不能与多个延迟脚本一起工作
- 将脚本添加到 DOM 后,JQuery 不能在 Watir 中使用 PhantomJS
- jQuery脚本可以在本地maschine上运行,但不能在网络主机上运行
- 这个脚本在firefox中工作,但可以'我不能用IE 7、8、9