正在添加具有正确url的iframe



我想加载一个iframe,这就是我所做的

document.getElementsByName('iFrameName')[0].src = url;

但是它将文件的url附加到当前url上,例如。www.website.com/currentpage

因此url不是www.website.com/file.html

现在是www.website.com/currentpage/file.html

我该怎么做我想要的

您可以尝试使用Jquery而不是javascript。使用以下代码在iframe中设置属性。

$('iframeName').attr('src', 'url');

如果要加载iframe,请使用load方法。

$('iframeId').load('currentPageUrl.html #iframeId');

使用setAttribute函数设置"src"属性及其值;"引用集属性"(Refernce Set Attribute(也可以参见上面的示例。

Element.setAttribute(名称、值(;

最新更新