zoukankan      html  css  js  c++  java
  • onbeforeunload 的使用

    原文发布时间为:2008-10-20 —— 来源于本人的百度文章 [由搬家工具导入]

    onbeforeunload

    可以在页面关闭,刷新,跳转时弹出提示信息,防止意外的跳转使得当前页的表单内容被清空。如果用onuload的话会使页面关闭之后才执行事件。所以,还是推荐使用这个onbeforeunload

    -----------------------------------
    用法:

    • object.onbeforeunload = handler
    • <element onbeforeunload = “handler” … ></element>

    描述:
    事件触发的时候弹出一个有确定和取消的对话框,确定则离开页面,取消则继续待在本页。
    handler可以设一个返回值作为该对话框的显示文本。

    触发于:

    • 关闭浏览器窗口
    • 通过地址栏或收藏夹前往其他页面的时候
    • 点击返回,前进,刷新,主页其中一个的时候
    • 点击 一个前往其他页面的url连接的时候
    • 调用以下任意一个事件的时候:click,document write,document open,document close,window close ,window navigate ,window NavigateAndFind,location replace,location reload,form submit.
    • 当用window open打开一个页面,并把本页的window的名字传给要打开的页面的时候。
    • 重新赋予location.href的值的时候。
    • 通过input type=”submit”按钮提交一个具有指定action的表单的时候。

    可以用在以下元素:
    BODY, FRAMESET, window

    平台支持:
    IE4+/Win, Mozilla 1.7a+, Netscape 7.2+, Firefox0.9+
    三大主流浏览器中firefox和IE都支持onbeforeunload事件,opera尚未支持
    -----------------------------------

    范例:
    1.
    <script>
    function window.onbeforeunload(){
    return"文字提示信息";
    }
    </script>
    2.
    <body onbeforeunload="";>

    缺陷:
    会出现一个确认离开当前页面的提示框,尚不知道如何去除...

  • 相关阅读:
    XML(学习笔记)
    css样式学习笔记
    Request(对象)
    sql一些错误修改的总结
    转载(如何学习C#)
    sql server(学习笔记2 W3Cschool)
    sql sqrver(学习笔记1 W3Cschool)
    关于 flutter开发碰到的各种问题,有的已经解决有的一直没解决或者用其他方法替代
    关于 Flutter IOS build It appears that your application still contains the default signing identifier.
    关于 flutter本地化问题 The getter 'pasteButtonLabel' was called on null
  • 原文地址:https://www.cnblogs.com/handboy/p/7148419.html
Copyright © 2011-2022 走看看