阻止用户在iframe内导航

时间:2018-06-11 00:29:55

标签: javascript html html5 iframe

因为我允许在iframe加载后运行javascript行

我执行了这个脚本

window.onbeforeunload = function(e) {e.preventDefault();} 
// it makes the user navigating without issues

我试过这个

window.onbeforeunload = function() {return '';} 
// it promot a confirmation message if the use will leave the page or not

任何其他解决方案?

1 个答案:

答案 0 :(得分:1)

如何覆盖链接的点击事件处理程序?

window.onload = function() {
    var links = document.getElementsByTagName("a");
    for(var i in links)
        links[i].onclick = function() {return false; };
};