一般用于内网的网站,嵌套了其他网站的链接页面,为保证友好显示,让其不显示 404 错误,即使用 js 监测页面能否正常打开,否则隐藏 iframe 框架。演示的 Demo 代码如下:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
<script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script></head><body> <iframe src="https://www.qhw.jw/server/564.html" id="weather" allowtransparency="true" frameborder="0" width="330" height="350" scrolling="no"></iframe> <script> var weather = $("#weather"); var iframeUrl = weather.attr("src"); $.ajax({url: iframeUrl,
type: "GET",
dataType: 'jsonp',
timeout: 2000,
complete: function(res) { if (res.status == 200) {weather.show();
} else {weather.hide();
}
}
})
</script></body></html>
在实际应用过程中,发现并不完全有用,原因未知,仅供参考。
专业提供WordPress主题安装、深度汉化、加速优化等各类网站建设服务,详询在线客服!
