我有一个转到网站的iframe,但我想这样做,如果无法访问该网站,它就会被隐藏。
如果可以,请使用http://weather.gc.ca/wxlink/wxlink.html?cityCode=on-143&lang=e
以便于演示。
提前致谢!
答案 0 :(得分:2)
你添加这个
<iframe src='' frameborder='0' width="800" height="600" onError="location.href='offline.jpg'"></iframe>
<img src="yourpath/onlinetestimg.jpg" width="1" height="1" style="visibility:hidden" onError="document.getElementById('iframe').innerHTML = '<img src=\'offline.jpg\'>'">
答案 1 :(得分:0)
关于网站离线,我猜你可以使用这种解决方法:
$('<img/>', {
id: "_tmpIMG",
src: "http://weather.gc.ca/weathericons/00.gif"
}).hide().on({
load: siteOnline,
error: siteNotOnline
}).appendTo('body');
function siteNotOnline(){
alert('site not online');
$('#_tmpIMG').remove();
$('#iframe').hide();
}
function siteOnline(){
alert('site online');
$('#_tmpIMG').remove();
}