{"id":69,"date":"2013-06-05T09:03:24","date_gmt":"2013-06-05T09:03:24","guid":{"rendered":"http:\/\/www.tvarwebu.cz\/blog\/?p=69"},"modified":"2023-10-27T12:47:16","modified_gmt":"2023-10-27T12:47:16","slug":"onbeforeunload-fun","status":"publish","type":"post","link":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/","title":{"rendered":"OnBeforeUnload fun"},"content":{"rendered":"<p>Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors.<\/p>\n<p>So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not understand, that return value NULL is supposed to mean &#8216;Do not show the confirm&#8217;.<\/p>\n<pre>\r\nvar origOnBeforeUnload = window.onbeforeunload;\r\nwindow.onbeforeunload = function(event) {\r\n  if(typeof origOnBeforeUnload === 'function') {\r\n    return origOnBeforeUnload(event);\r\n  }\r\n}\r\n<\/pre>\n<p>We needed to implement little more robust checking, and when we do not want to show a message, you need to not return anything.<\/p>\n<pre>\r\nvar origOnBeforeUnload = window.onbeforeunload;\r\nwindow.onbeforeunload = function(event) {\r\n  \/\/do any code you want to\r\n  if(typeof origOnBeforeUnload === 'function') {\r\n    var out = origOnBeforeUnload(event);\r\n    if(typeof out !== 'undefined' &amp;&amp; out !== null &amp;&amp; out !== false)\r\n      return out;\r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-uncategorized","item-wrap"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Martin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Tv\u00e1\u0159 Webu Blog | Blog about webdesign, web, adroid and iphone development\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"OnBeforeUnload fun | Tv\u00e1\u0159 Webu Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2013-06-05T09:03:24+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-10-27T12:47:16+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"OnBeforeUnload fun | Tv\u00e1\u0159 Webu Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#article\",\"name\":\"OnBeforeUnload fun | Tv\\u00e1\\u0159 Webu Blog\",\"headline\":\"OnBeforeUnload fun\",\"author\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/author\\\/martin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/#organization\"},\"datePublished\":\"2013-06-05T09:03:24+00:00\",\"dateModified\":\"2023-10-27T12:47:16+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#webpage\"},\"articleSection\":\"Uncategorized\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"name\":\"Uncategorized\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"position\":2,\"name\":\"Uncategorized\",\"item\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/category\\\/uncategorized\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#listItem\",\"name\":\"OnBeforeUnload fun\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#listItem\",\"position\":3,\"name\":\"OnBeforeUnload fun\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/category\\\/uncategorized\\\/#listItem\",\"name\":\"Uncategorized\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/#organization\",\"name\":\"Tv\\u00e1\\u0159 Webu Blog\",\"description\":\"Blog about webdesign, web, adroid and iphone development\",\"url\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/author\\\/martin\\\/#author\",\"url\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/author\\\/martin\\\/\",\"name\":\"Martin\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/\",\"name\":\"OnBeforeUnload fun | Tv\\u00e1\\u0159 Webu Blog\",\"description\":\"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/2013\\\/06\\\/onbeforeunload-fun\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/author\\\/martin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/author\\\/martin\\\/#author\"},\"datePublished\":\"2013-06-05T09:03:24+00:00\",\"dateModified\":\"2023-10-27T12:47:16+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/\",\"name\":\"Tv\\u00e1\\u0159 Webu Blog\",\"description\":\"Blog about webdesign, web, adroid and iphone development\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tvarwebu.cz\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"OnBeforeUnload fun | Tv\u00e1\u0159 Webu Blog","description":"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not","canonical_url":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#article","name":"OnBeforeUnload fun | Tv\u00e1\u0159 Webu Blog","headline":"OnBeforeUnload fun","author":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/author\/martin\/#author"},"publisher":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/#organization"},"datePublished":"2013-06-05T09:03:24+00:00","dateModified":"2023-10-27T12:47:16+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#webpage"},"articleSection":"Uncategorized"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tvarwebu.cz\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tvarwebu.cz\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tvarwebu.cz\/blog\/category\/uncategorized\/#listItem","name":"Uncategorized"}},{"@type":"ListItem","@id":"https:\/\/www.tvarwebu.cz\/blog\/category\/uncategorized\/#listItem","position":2,"name":"Uncategorized","item":"https:\/\/www.tvarwebu.cz\/blog\/category\/uncategorized\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#listItem","name":"OnBeforeUnload fun"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tvarwebu.cz\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#listItem","position":3,"name":"OnBeforeUnload fun","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tvarwebu.cz\/blog\/category\/uncategorized\/#listItem","name":"Uncategorized"}}]},{"@type":"Organization","@id":"https:\/\/www.tvarwebu.cz\/blog\/#organization","name":"Tv\u00e1\u0159 Webu Blog","description":"Blog about webdesign, web, adroid and iphone development","url":"https:\/\/www.tvarwebu.cz\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tvarwebu.cz\/blog\/author\/martin\/#author","url":"https:\/\/www.tvarwebu.cz\/blog\/author\/martin\/","name":"Martin"},{"@type":"WebPage","@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#webpage","url":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/","name":"OnBeforeUnload fun | Tv\u00e1\u0159 Webu Blog","description":"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/author\/martin\/#author"},"creator":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/author\/martin\/#author"},"datePublished":"2013-06-05T09:03:24+00:00","dateModified":"2023-10-27T12:47:16+00:00"},{"@type":"WebSite","@id":"https:\/\/www.tvarwebu.cz\/blog\/#website","url":"https:\/\/www.tvarwebu.cz\/blog\/","name":"Tv\u00e1\u0159 Webu Blog","description":"Blog about webdesign, web, adroid and iphone development","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tvarwebu.cz\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Tv\u00e1\u0159 Webu Blog | Blog about webdesign, web, adroid and iphone development","og:type":"article","og:title":"OnBeforeUnload fun | Tv\u00e1\u0159 Webu Blog","og:description":"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not","og:url":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/","article:published_time":"2013-06-05T09:03:24+00:00","article:modified_time":"2023-10-27T12:47:16+00:00","twitter:card":"summary_large_image","twitter:title":"OnBeforeUnload fun | Tv\u00e1\u0159 Webu Blog","twitter:description":"Yesterday, we have encountered issues regarding window.onbeforeunload function. We have implemented checking of json transport issues, but this throws errors, when the page is beeing unloaded and we needed to hide these errors. So we implemented onBeforeUnload function, however we needed to preserve any previous onBeforeUnload functions. The issue here is that IE does not"},"aioseo_meta_data":{"post_id":"69","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":true,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2025-07-15 07:33:19","updated":"2025-07-15 07:43:22","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tvarwebu.cz\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tvarwebu.cz\/blog\/category\/uncategorized\/\" title=\"Uncategorized\">Uncategorized<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tOnBeforeUnload fun\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tvarwebu.cz\/blog"},{"label":"Uncategorized","link":"https:\/\/www.tvarwebu.cz\/blog\/category\/uncategorized\/"},{"label":"OnBeforeUnload fun","link":"https:\/\/www.tvarwebu.cz\/blog\/2013\/06\/onbeforeunload-fun\/"}],"_links":{"self":[{"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":4,"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/posts\/69\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tvarwebu.cz\/blog\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}