技术频道导航
HTML/CSS
.NET技术
IIS技术
PHP技术
Js/JQuery
Photoshop
Fireworks
服务器技术
操作系统
网站运营

赞助商

分类目录

赞助商

最新文章

搜索

iframe地址赋值失败的原因

作者:admin    时间:2018-1-18 15:14:49    浏览:

iframe地址我想做成这样:

<iframe src="http://anydomain.com/frame.php?ref=http://currentpageurl.com/dir"></iframe>

于是我使用这样的写法:

<iframe src="http://localhost/<script type="text/javascript">document.write(window.location.pathname);</script>.html" frameborder="0" scrolling="no" onload="resizeIframe(this)" />

但是并没有达到我想要的效果,却提示错误了:

从客户端(<)中检测到有潜在危险的 Request.Path 值。:
地址: http://localhost/%3Cscript%20type=

可以知道,iframe地址直接用 document.write 输出是不行的。

那么该如何实现我原先的想法呢?

其实还是用JS或JQuery来实现,只不过写法跟我上面的写法有所不同。下面介绍用最简单的JS来实现,代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iframe src赋值的方法</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<iframe frameborder="1" id="barframe" ></iframe>
</body>
</html>
<script type="text/javascript">
document.getElementById("barframe").src = "http://anydomain.com/frame.php?ref=http://localhost/" + window.location.pathname;
</script>

代码分析,先输出iframe的html,再用JS给iframe的src赋值。

execcodegetcode

您可能对以下文章也感兴趣

标签: iframe  frame  
x
  • 站长推荐
/* 左侧显示文章内容目录 */