{"id":205,"date":"2010-07-01T19:56:29","date_gmt":"2010-07-01T14:26:29","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=205"},"modified":"2010-07-01T20:41:21","modified_gmt":"2010-07-01T15:11:21","slug":"forcing-javascript-to-abort-stop-javascript-execution-at-any-time","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/javascript\/forcing-javascript-to-abort-stop-javascript-execution-at-any-time\/","title":{"rendered":"forcing javascript to abort &#8211; stop javascript execution at any time"},"content":{"rendered":"<p>How do we abort  JavaScript execution at any instance even inside a loop. <\/p>\n<p>Create a function with a name jsexit or jsabort<br \/>\nand have this as its code<\/p>\n<pre lang='javascript'>\r\nfunction javascript_abort()\r\n{\r\n   throw new Error('This is not an error. This is just to abort javascript');\r\n}\r\n\r\n<\/pre>\n<p>instead of the error string which i have given you can give any string you want. This is really working well for me.<\/p>\n<p>call it anywhere like javascript_abort()<br \/>\nfor example<\/p>\n<pre lang='javascript'>\r\n\/\/ assume that you have this code inside a nested function.\r\nfor(var i=0;i<10;i++)\r\n{\r\n     if(i==5)javascript_abort();\r\n     alert(i);\r\n}\r\n\/\/so at any place it will stop the execution.\r\n<\/pre>\n<p>But in IE browsers you will see an yellow exclamation to indicate that there is an error in the javascript. <\/p>\n<p>Otherwise every thing is perfect i believe. In other browsers this will not appear. If you have enabled error reporting add-on for firefox then it would show a graphic notification. that too is not at all a problem.<\/p>\n<p>If anybody (the users) clicks the yellow exclamation in IE they see this string as error message 'This is not an error. This is just to abort javascript'.<\/p>\n<p>But still i need an option to exit javascript execution without making IE or any other browsers that an error has occured when a new error has been thrown.<\/p>\n<p>I would like to have comments, suggestion and objections about this because i would like to know what people think about this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How do we abort JavaScript execution at any instance even inside a loop. Create a function with a name jsexit or jsabort and have this as its code function javascript_abort() { throw new Error(&#8216;This is not an error. This is just to abort javascript&#8217;); } instead of the error string which i have given you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[24],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/205"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=205"}],"version-history":[{"count":4,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/205\/revisions"}],"predecessor-version":[{"id":207,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/205\/revisions\/207"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}