我有一個離線的HTML,我添加一個iframe,它重定向到一個網站,如果有可用的連接。但如果沒有互聯網連接,iframe將重定向到脫機頁面/ html。HTML5 Iframe重定向的情況下檢查連接[編輯]
有人可以向我解釋我需要使用哪些代碼?我正在使用檢查互聯網連接腳本,但我不知道什麼代碼,我需要插入內部JavaScript交換警報('你是網上')>重定向到在線網站和警報('你是脫機「)>重定向到離線頁面
if(navigator.onLine)
{
alert('You are Online');
}
else
{
alert('You are Offline')
}
<iframe height="500px" width="100%" src="http://example.github.io/" id="foo"></iframe>
<div style="text-align:center"> This Iframe </div>
末iframe標籤後,您可以使用NOFRAME標籤這個環節不工作 –
http://stackoverflow.com/questions/15273042/catch-error-if-iframe-src-fails-to-load-error -refused-to-display-http-ww –