{"id":506,"date":"2015-07-10T17:22:51","date_gmt":"2015-07-10T11:52:51","guid":{"rendered":"http:\/\/mairwa.com\/wordpress\/?p=506"},"modified":"2015-07-10T17:22:51","modified_gmt":"2015-07-10T11:52:51","slug":"windows-location-navigation-error","status":"publish","type":"post","link":"http:\/\/mairwa.com\/wordpress\/?p=506","title":{"rendered":"windows.location navigation error"},"content":{"rendered":"<p>If beforeupload function is attached to windows and any event\/ function changes the windows.location and we choose &#8220;Stay on this page&#8221; it will through error.<\/p>\n<p>We need to use try catch for the solution.<\/p>\n<p>binding beforunload event for page<br \/>\n$(window).on(&#8216;beforeunload&#8217;, function(e){ return &#8220;must&#8221; \u00a0});<\/p>\n<p><strong>following code is solution for if we called ajax call and using callback with change windows location<\/strong><\/p>\n<p>try<span style=\"line-height: 1.5;\">{<\/span><\/p>\n<p>if ($(&#8220;#Anchor&#8221;).length &gt; 0) {<br \/>\n$(&#8220;#Anchor&#8221;).attr(&#8220;href&#8221;, url).get(0).click();<br \/>\n} else {<br \/>\n$(&#8220;&lt;A&gt;&#8221;).attr(&#8220;id&#8221;, &#8220;Anchor&#8221;).attr(&#8220;href&#8221;, url).appendTo(document.body).get(0).click();<br \/>\n}<br \/>\n} catch (e) { }<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">If beforeupload function is attached to windows and any event\/ function changes the windows.location and we choose &#8220;Stay on this page&#8221; it will through error. We need to use try catch for the solution. binding beforunload event for page $(window).on(&#8216;beforeunload&#8217;, function(e){ return &#8220;must&#8221; \u00a0}); following code is solution for if we called ajax call and using callback with change windows&hellip; <a href=\"http:\/\/mairwa.com\/wordpress\/?p=506\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-506","post","type-post","status-publish","format-standard","hentry","category-jquery","xfolkentry"],"_links":{"self":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=506"}],"version-history":[{"count":1,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/506\/revisions"}],"predecessor-version":[{"id":507,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/506\/revisions\/507"}],"wp:attachment":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}