父窗口域位于 Iframe src 页面前面

Parent window domain prepended to Iframe src page

本文关键字:src 前面 Iframe 窗口      更新时间:2023-09-26

我通过以下方式使用javascript插入iframe:

var s ="<p><iframe name=&quot;searchf&quot; src=&quot;http://www.google.com&quot; frameborder=&quot;0&quot; width=&quot;100%&quot; height=&quot;350&quot;></iframe></p>";
var para = document.createElement("div");
para.innerHTML = s;
var element =  document.getElementById("some_div_id");
var child = document.getElementById("some_fieldset_id");
element.insertBefore(para,child);

假设父窗口域是 http://www.parentwindowdomain.com/example1 。问题是 iframe src 页面以某种方式被解释为父窗口域名附加到指定的 src 域。例如,生成的 iframe src 页面地址将被错误地http://www.parentwindowdomain.com/example1/"http://www.google.com"

有没有办法覆盖它,以便在这种情况下,iframe src 页面将被http://www.google.com

你能试试这个吗,我觉得它更整洁。

http://jsfiddle.net/qpkp5sb2/

var s = document.createElement("iframe");
s.setAttribute("name", "searchf");
s.setAttribute("src", "http://www.example.com");
s.setAttribute("frameborder", "0");
s.setAttribute("width", "100%");
s.setAttribute("height", "350");
var pp = document.createElement("p");
pp.appendChild(s);
var para = document.createElement("div");
para.appendChild(pp);
var element =  document.getElementById("some_div_id");
var child = document.getElementById("some_fieldset_id");
element.insertBefore(para,child);
console.log(s);