繁体   English   中英

Javascript location.replace和iframe

[英]Javascript location.replace and iframe

以下程序可以在chrome中工作,但是在firefox中无法正常工作,我需要刷新页面,否则页面将是空白的!

firefox会跳出商店橱窗使用iframe无法正常工作,有办法吗?

谢谢大家!

var url = "/card/"+dl_path;
SaveFrame.document.location.replace(url);

<iframe id="SaveFrame" style="display: none"></iframe>

如果你使用jQuery,你可以使用像$('#saveFrame').attr('src', url) 它适用于所有浏览器。

尝试

document.getElementById('SaveFrame').src="http://google.com/";

通过在全局范围内隐含创建的变量来寻址元素是一种专有的“Internet Explorer”方式,最有可能在其他浏览器中不起作用(尽管Chrome由于兼容性原因支持这种方式)。 您应该始终通过Dom选择方法通过以下方式寻址元素:

document.querySelector(id)
// or
document.getElementById(id)

对于你的情况,将是:

document.getElementId('SaveFrame').contentDocument.location.replace(url);
// or
document.getElementId('SaveFrame').src= url;

这应该工作,它是快速加载的网页它对我有用...

onmouseover="window.open ('http://www.yourpage.com','YourTargetName'); this.onmouseover=null;"


代码“this.onmouseover = null;” 意味着它只应在加载时执行ONCE并且不在第二个鼠标上重复该属性,如果您希望它在第二个鼠标上重复该属性,则删除“this.onmouseover = null;” 从代码开始,每次鼠标结束时都加载它:

onmouseover="window.open ('http://www.yourpage.com','YourTargetName');"


例:

<a href="#" onmouseover="window.open ('http://www.yourpage.com','YourTargetName');">
My Link</a>



或试试这个:

OnClick="window.open ('http://www.yourpage.com','YourTargetName');"

例:

<a href="#" OnClick="window.open ('http://www.yourpage.com','YourTargetName');">
My Link</a>

要么

<a href="javascript:window.open ('http://www.yourpage.com','YourTargetName');">
My Link</a>

要么

如果您希望在加载页面或框架时使用window.location.replace不更新历史记录,请使用如下所示的链接:

<a href="#" onclick="YourTargetName.location.replace ('http://www.YourPage.com');">
The targeted Link</a>

要么

<a href="javascript:YourTargetName.location.replace ('http://www.YourPage.com');">
The targeted Link</a>


信息:对于这个脚本,所有onclickonmouseoveronmouseoutonloadhref="javascript:"都可以。



注意:请记住,iframe必须具有name =“YourTargetName”,例如看起来像这样:

<iframe id="SaveFrame" style="display: none" name="YourTargetName"></iframe>


信息: window.openwindow.location.replaceYourTargetName.location.replace之间的区别在于:
- window.open在浏览器历史记录中加载。
- window.location.replaceYourTargetName.location.replace不加载历史记录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM