将iframe插入站点而不使用document.write
问题描述:
我们的网站使用iframe来显示我们提供的产品库,最近iframe停止在Google Chrome中加载,因为它们停止支持document.write。我们需要一种解决方案,以与我们一样的方式显示页面,但不使用document.write。我是一个新手,并尝试了几种解决方案,但没有任何工作。将iframe插入站点而不使用document.write
我们所拥有的:
<script language="JavaScript">
<!--
var ss='<span style="font-size: small;"><b>NOTICE:</b> If you are having
trouble finding a pattern, try searching the first three letters of the
pattern name in the search bar. Also, be aware that some sheers may be
photographed with a window pane to show sheer quality.<br>If you are using
Google Chrome and have an issue viewing the library, please switch to another
browser.</span><br><br>';
var upper_limit = 500000000;
//-->
document.write(ss);
function getIP(json) {
document.write('<iframe frameborder="0" marginheight="0" width="100%"
height="700" src=" ' + 'http://client.richloomfabrics.com/cgi-bin/Wdrv01?
&PARPAR=CON&MELMEL=ALL&PTYPTY=UPH&IPAIPA=' + json.ip +
'&IPACOK=' + RandomNumber(upper_limit) + '&PGMPGM=WC033&>
</iframe>');
}
</script>
<script type="application/javascript" src="https://api.ipify.org?
format=jsonp&callback=getIP"></script>
我们使用购物车,这就是为什么我们需要的随机数和IP。我已经尝试了一些我见过的解决方案,但对此不太了解,无法正确编辑。任何人都可以让我朝正确的方向发展吗?
答
在非常简单的情况下,你可以使用的body
innerHTML
财产,像这样
<script language="JavaScript">
<!--
var ss='<span style="font-size: small;"><b>NOTICE:</b> If you are having
trouble finding a pattern, try searching the first three letters of the
pattern name in the search bar. Also, be aware that some sheers may be
photographed with a window pane to show sheer quality.<br>If you are using
Google Chrome and have an issue viewing the library, please switch to another
browser.</span><br><br>';
var upper_limit = 500000000;
//-->
document.body.innerHTML += ss;
function getIP(json) {
document.body.innerHTML += '<iframe frameborder="0" marginheight="0" width="100%"
height="700" src=" ' + 'http://client.richloomfabrics.com/cgi-bin/Wdrv01?
&PARPAR=CON&MELMEL=ALL&PTYPTY=UPH&IPAIPA=' + json.ip +
'&IPACOK=' + RandomNumber(upper_limit) + '&PGMPGM=WC033&>
</iframe>';
}
</script>
<script type="application/javascript" src="https://api.ipify.org?
format=jsonp&callback=getIP"></script>
+0
感谢您的建议,不幸的是我无法得到任何这些工作。事实上,当我改变我对这些建议的看法时,甚至连中的类型都不再显示,所以某些东西肯定不起作用。这是在Squarespace网站上,我不知道这是否有所作为。另外,当谈到JS时,我真的是新手,我知道一些CSS和HTML,但仅此而已,不幸的是,这里没有人会更好。 – jpmd0302
答
您还可以使用的appendChild
var iframeElem = document.createElement('iframe');
iframeElem.src = 'https://www.google.com';
document.body.appendChild(iframeElem);
是这部分的一些HTML元素的内部?如果它是带有id =“documentWriteElement”的元素,则可以用document.getElementById(“documentWriteElement”)。innerHTML'替换document.write。 – Walk
但是,我建议你看看'document.createElement'和'element.appendChild'而不是'innerHTML'。 – Walk