{"id":53550,"date":"2024-12-03T10:44:41","date_gmt":"2024-12-03T02:44:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53550\/"},"modified":"2024-12-03T10:44:41","modified_gmt":"2024-12-03T02:44:41","slug":"chrome-%e6%b5%8f%e8%a7%88%e5%99%a8%e5%85%b3%e9%97%ad%e6%97%b6%e4%b8%8d%e8%a7%a6%e5%8f%91-onbeforeunload-%e4%ba%8b%e4%bb%b6%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53550\/","title":{"rendered":"Chrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Chrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300aChrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241201\/1733060568674c67d89b531.jpg\" class=\"aligncenter\" title=\"Chrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Chrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>Chrome onbeforeunload \u4e8b\u4ef6\u5931\u6548\uff0c\u66ff\u4ee3\u65b9\u6848<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 Chrome \u6d4f\u89c8\u5668\u65f6\uff0c\u53d1\u73b0 window.onbeforeunload \u4e8b\u4ef6\u5728\u5173\u95ed\u6d4f\u89c8\u5668\u65f6\u4e0d\u89e6\u53d1\u3002\u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u5b58\u5728\u4ee5\u4e0b\u66ff\u4ee3\u65b9\u6848\uff1a<\/p>\n<ul>\n<li><strong>beforeunload \u4e8b\u4ef6<\/strong><\/li>\n<\/ul>\n<p>\u8be5\u4e8b\u4ef6\u5728\u9875\u9762\u5373\u5c06\u5378\u8f7d\u65f6\u89e6\u53d1\uff0c\u5305\u62ec\u5173\u95ed\u6d4f\u89c8\u5668\u3001\u5207\u6362\u6807\u7b7e\u9875\u4ee5\u53ca\u4ece\u9875\u9762\u5bfc\u822a\u5230\u5176\u4ed6\u9875\u9762\u3002\u4e0d\u8fc7\uff0c\u4e0e onbeforeunload \u4e8b\u4ef6\u4e0d\u540c\uff0cbeforeunload \u4e8b\u4ef6\u65e0\u6cd5\u963b\u6b62\u9875\u9762\u5378\u8f7d\u3002<\/p>\n<ul>\n<li><strong>unload \u4e8b\u4ef6<\/strong><\/li>\n<\/ul>\n<p>\u8be5\u4e8b\u4ef6\u5728\u9875\u9762\u5378\u8f7d\u540e\u89e6\u53d1\uff0c\u4f46\u5728\u6b64\u4e8b\u4ef6\u4e2d\uff0c\u65e0\u6cd5\u963b\u6b62\u9875\u9762\u5378\u8f7d\u6216\u4fee\u6539\u9875\u9762\u3002<\/p>\n<ul>\n<li><strong>\u9875\u9762\u53ef\u89c1\u6027 API<\/strong><\/li>\n<\/ul>\n<p>\u6b64 API \u63d0\u4f9b\u9875\u9762\u53ef\u89c1\u6027\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u68c0\u6d4b\u9875\u9762\u4f55\u65f6\u8fdb\u5165\u540e\u53f0\u3002\u5f53\u9875\u9762\u8fdb\u5165\u540e\u53f0\u65f6\uff0c\u53ef\u4ee5\u663e\u793a\u4e00\u6761\u63d0\u793a\u6d88\u606f\uff0c\u8be2\u95ee\u7528\u6237\u662f\u5426\u8981\u79bb\u5f00\u9875\u9762\u3002<\/p>\n<ul>\n<li><strong>\u786e\u8ba4\u5bf9\u8bdd\u6846<\/strong><\/li>\n<\/ul>\n<p>\u53ef\u4ee5\u5728\u5173\u95ed\u6d4f\u89c8\u5668\u4e4b\u524d\u663e\u793a\u4e00\u4e2a\u786e\u8ba4\u5bf9\u8bdd\u6846\uff0c\u8be2\u95ee\u7528\u6237\u662f\u5426\u8981\u79bb\u5f00\u9875\u9762\u3002\u8fd9\u53ef\u4ee5\u5728\u7528\u6237\u9000\u51fa\u4e4b\u524d\u5411\u5176\u63d0\u4f9b\u6700\u540e\u7684\u786e\u8ba4\u3002<\/p>\n<p><strong>\u6d4b\u8bd5\u7ed3\u679c<\/strong><\/p>\n<p>\u5728 Chrome 73.0.3683.103 \u7248\u672c\u4e2d\u8fdb\u884c\u6d4b\u8bd5\u53d1\u73b0\uff1a<\/p>\n<ul>\n<li>\u76f4\u63a5\u5173\u95ed\u9875\u9762\u4e0d\u4f1a\u89e6\u53d1 onbeforeunload \u4e8b\u4ef6\u3002<\/li>\n<li>\u4e0e\u9875\u9762\u4ea4\u4e92\uff08\u5982\u5355\u51fb\u94fe\u63a5\uff09\u540e\u5173\u95ed\u9875\u9762\uff0c\u4f1a\u89e6\u53d1 onbeforeunload \u4e8b\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aChrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u7236\u5143\u7d20\u4ec5\u8bbe\u7f6e Line-height \u5bf9\u5b50\u5143\u7d20\u9ad8\u5ea6\u7684\u5f71\u54cd\uff1a\u884c\u5185\u5757\u7ea7\u5143\u7d20\u4e0e\u5757\u7ea7\u5143\u7d20\u6709\u4ec0\u4e48\u533a\u522b\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Chrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f \u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300aChrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01 Chrome onbeforeunload \u4e8b\u4ef6\u5931\u6548\uff0c\u66ff\u4ee3\u65b9\u6848 \u5728\u4f7f\u7528 Chrome \u6d4f\u89c8\u5668\u65f6\uff0c\u53d1\u73b0 window.onbeforeunload \u4e8b\u4ef6\u5728\u5173\u95ed\u6d4f\u89c8\u5668\u65f6\u4e0d\u89e6\u53d1\u3002\u5bf9\u4e8e\u6b64\u95ee\u9898\uff0c\u5b58\u5728\u4ee5\u4e0b\u66ff\u4ee3\u65b9\u6848\uff1a beforeunload \u4e8b\u4ef6 \u8be5\u4e8b\u4ef6\u5728\u9875\u9762\u5373\u5c06\u5378\u8f7d\u65f6\u89e6\u53d1\uff0c\u5305\u62ec\u5173\u95ed\u6d4f\u89c8\u5668\u3001\u5207\u6362\u6807\u7b7e\u9875\u4ee5\u53ca\u4ece\u9875\u9762\u5bfc\u822a\u5230\u5176\u4ed6\u9875\u9762\u3002\u4e0d\u8fc7\uff0c\u4e0e onbeforeunload \u4e8b\u4ef6\u4e0d\u540c\uff0cbeforeunload \u4e8b\u4ef6\u65e0\u6cd5\u963b\u6b62\u9875\u9762\u5378\u8f7d\u3002 unload \u4e8b\u4ef6 \u8be5\u4e8b\u4ef6\u5728\u9875\u9762\u5378\u8f7d\u540e\u89e6\u53d1\uff0c\u4f46\u5728\u6b64\u4e8b\u4ef6\u4e2d\uff0c\u65e0\u6cd5\u963b\u6b62\u9875\u9762\u5378\u8f7d\u6216\u4fee\u6539\u9875\u9762\u3002 \u9875\u9762\u53ef\u89c1\u6027 API \u6b64 API \u63d0\u4f9b\u9875\u9762\u53ef\u89c1\u6027\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u68c0\u6d4b\u9875\u9762\u4f55\u65f6\u8fdb\u5165\u540e\u53f0\u3002\u5f53\u9875\u9762\u8fdb\u5165\u540e\u53f0\u65f6\uff0c\u53ef\u4ee5\u663e\u793a\u4e00\u6761\u63d0\u793a\u6d88\u606f\uff0c\u8be2\u95ee\u7528\u6237\u662f\u5426\u8981\u79bb\u5f00\u9875\u9762\u3002 \u786e\u8ba4\u5bf9\u8bdd\u6846 \u53ef\u4ee5\u5728\u5173\u95ed\u6d4f\u89c8\u5668\u4e4b\u524d\u663e\u793a\u4e00\u4e2a\u786e\u8ba4\u5bf9\u8bdd\u6846\uff0c\u8be2\u95ee\u7528\u6237\u662f\u5426\u8981\u79bb\u5f00\u9875\u9762\u3002\u8fd9\u53ef\u4ee5\u5728\u7528\u6237\u9000\u51fa\u4e4b\u524d\u5411\u5176\u63d0\u4f9b\u6700\u540e\u7684\u786e\u8ba4\u3002 \u6d4b\u8bd5\u7ed3\u679c \u5728 Chrome 73.0.3683.103 \u7248\u672c\u4e2d\u8fdb\u884c\u6d4b\u8bd5\u53d1\u73b0\uff1a \u76f4\u63a5\u5173\u95ed\u9875\u9762\u4e0d\u4f1a\u89e6\u53d1 onbeforeunload \u4e8b\u4ef6\u3002 \u4e0e\u9875\u9762\u4ea4\u4e92\uff08\u5982\u5355\u51fb\u94fe\u63a5\uff09\u540e\u5173\u95ed\u9875\u9762\uff0c\u4f1a\u89e6\u53d1 onbeforeunload \u4e8b\u4ef6\u3002 \u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aChrome \u6d4f\u89c8\u5668\u5173\u95ed\u65f6\u4e0d\u89e6\u53d1 `onbeforeunload` \u4e8b\u4ef6\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01 \u7236\u5143\u7d20\u4ec5\u8bbe\u7f6e Line-height \u5bf9\u5b50\u5143\u7d20\u9ad8\u5ea6\u7684\u5f71\u54cd\uff1a\u884c\u5185\u5757\u7ea7\u5143\u7d20\u4e0e\u5757\u7ea7\u5143\u7d20\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53550","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53550"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53550\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}