我试图通过下面的 href 链接实现两件事。首先,我想启动一个弹出窗口。完毕。接下来,我希望弹出窗口显示 iframe。这也很容易完成until我意识到我需要将 href 链接文本作为 iframe src 中的参数传递。
例如,iframe 不会加载到我的弹出窗口中,除非它src="http://localhost:8080/test/document.html?OnSale"
我不明白为什么document.write
在我的 html 页面正文中不会打印出我尝试使用 href 链接中的 foo() 函数创建的动态 iframe...
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<a href="#" onclick="popup('popUpDiv')">
<img align="right" src="http://localhost:8080/test/img/close_img.png">
</a>
<script type="text/javascript">
function foo(obj)
{
test1 = "http://localhost:8080/test/document.html?"+obj.text;
document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>');
}
</div>
<a href="#" onclick="popup('popUpDiv');foo(this);">OnSale</a>
EDIT:这是我的完整 html 页面。一切都在 tomcat7 w/ win7 和 firefox 上本地运行。
<html>
<head>
<script type="text/javascript" src="http://localhost:8080/test/css-popup/css-pop.js"></script>
<link href="http://localhost:8080/test/css-popup/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<a href="#" onclick="popup('popUpDiv')">
<img align="right" src="http://localhost:8080/test/css-popup/x.png">
</a>
<script type="text/javascript">
function foo(obj){
test1 = "http://localhost:8080/test/document.html?"+obj.innerHTML;
document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>');
}
</script>
</div>
<a href="#" onclick="popup('popUpDiv');foo(this);">OnSale</a>
</body>
</html>
text
不是所有浏览器的标准,请尝试innerHTML
相反,
function foo(obj){
test1 = "http://localhost:8080/test/document.html?"+obj.innerHTML;
document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>');
}
在您共享整个代码后更新,
据我了解,您想要打开一个弹出窗口,并在其中显示动态创建的 iframe。但 document.write 适用于您当前的窗口。所以你必须首先处理你的弹出窗口。然后更改其内容。
尝试这个,
<html>
<head>
<script type="text/javascript" src="http://localhost:8080/test/css-popup/css-pop.js"></script>
<link href="http://localhost:8080/test/css-popup/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<a href="#" onclick="popup('popUpDiv')">
<img align="right" src="http://localhost:8080/test/css-popup/x.png">
</a>
<script type="text/javascript">
var popUpWindow;
function popup(n) {
popUpWindow = window.open(n);
}
function foo(obj){
test1 = "http://localhost:8080/test/document.html?"+obj.innerHTML;
popUpWindow.document.write('<iframe height="450" allowTransparency="true" frameborder="0" scrolling="yes" style="width:100%;" src="'+test1+'" type= "text/javascript"></iframe>');
}
</script>
</div>
<a href="#" onclick="popup('popUpDiv');foo(this);">OnSale</a>
</body>
</html>
And 这是现场演示 http://jsfiddle.net/U8wCc/1/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)