我体上的标签使用onload="myFunction()"
, 我使用JavaScript代码这样如何在用户试图离开页面窗口或关闭标签时显示弹出窗口?
function myFunction() {
//alert("Page is loaded");
document.getElementById("test").style.display = "block";
}
function hidePopup() {
// alert("Hidden");
document.getElementById("test").style.display = "none";
}
<div id="test" style="z-index: 20000;display: none;">
<div id="popup">
<div id="close" onclick="hidePopup()">x</div>
<div id="popup_img" class="hos_modal" style="height:900px; width:900px; margin:0 auto;">
<a href="javascript:void()" target="_blank"><img src="files/image.jpg" alt="free trial" style="width: auto; height: auto;"></a>
</div>
</div>
</div>
上面的代码被表示在加载浏览器时弹出。我还用onunload
和onmouseout
事件。
入住此http://v4-alpha.getbootstrap。 com/components/modal/ – Roy
@Roy感谢您的回复,我想用纯JavaScript来做到这一点。 –
我不明白,你需要在关闭标签上弹出显示?标签的ID在哪里?您需要在选项卡上触发mouseenter事件以显示弹出窗口 – Roy