2017-10-10 61 views
1

我們的網站使用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? 
&amp;PARPAR=CON&amp;MELMEL=ALL&amp;PTYPTY=UPH&amp;IPAIPA=' + json.ip + 
'&amp;IPACOK=' + RandomNumber(upper_limit) + '&amp;PGMPGM=WC033&amp;> 
</iframe>'); 

      } 
</script> 
<script type="application/javascript" src="https://api.ipify.org? 
format=jsonp&callback=getIP"></script> 

我們使用購物車,這就是爲什麼我們需要的隨機數和IP。我已經嘗試了一些我見過的解決方案,但對此不太瞭解,無法正確編輯。任何人都可以讓我朝正確的方向發展嗎?

+0

是這部分的一些HTML元素的內部?如果它是帶有id =「documentWriteElement」的元素,則可以用document.getElementById(「documentWriteElement」)。innerHTML'替換document.write。 – Walk

+0

但是,我建議你看看'document.createElement'和'element.appendChild'而不是'innerHTML'。 – Walk

回答

0

在非常簡單的情況下,你可以使用的bodyinnerHTML財產,像這樣

<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? 
&amp;PARPAR=CON&amp;MELMEL=ALL&amp;PTYPTY=UPH&amp;IPAIPA=' + json.ip + 
'&amp;IPACOK=' + RandomNumber(upper_limit) + '&amp;PGMPGM=WC033&amp;> 
</iframe>'; 

      } 
</script> 
<script type="application/javascript" src="https://api.ipify.org? 
format=jsonp&callback=getIP"></script> 
+0

感謝您的建議,不幸的是我無法得到任何這些工作。事實上,當我改變我對這些建議的看法時,甚至連中的類型都不再顯示,所以某些東西肯定不起作用。這是在Squarespace網站上,我不知道這是否有所作爲。另外,當談到JS時,我真的是新手,我知道一些CSS和HTML,但僅此而已,不幸的是,這裏沒有人會更好。 – jpmd0302

0

您還可以使用的appendChild

var iframeElem = document.createElement('iframe'); 
iframeElem.src = 'https://www.google.com'; 
document.body.appendChild(iframeElem); 
相關問題