将您的网站移到另一个网站时的警告消息

时间:2019-05-06 14:30:10

标签: javascript jquery html5

您如何为任何外部链接设置警告消息,以使用户知道他们正在离开您的网站并转到另一个网站?

<div class="row">
  <div class="col-lg-12">
    <div class="form-group">
      *For a list of all other forms not listed above that may be applicable - <a href="" target="_blank"><span class="noprint">(click here to print)</span></a>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用beforeunload函数执行此操作:

在Jquery中

$(window).bind('beforeunload', function(){
  return 'Are you sure you want to leave?';
});

使用Java语言

window.onbeforeunload = function(){
  return 'Are you sure you want to leave?';
};