{"id":377,"date":"2009-04-28T14:46:43","date_gmt":"2009-04-28T19:46:43","guid":{"rendered":"http:\/\/mikeconley.ca\/blog\/?p=377"},"modified":"2023-12-20T16:25:21","modified_gmt":"2023-12-20T21:25:21","slug":"overriding-firefoxs-windowalert-chapter-1","status":"publish","type":"post","link":"https:\/\/mikeconley.ca\/blog\/2009\/04\/28\/overriding-firefoxs-windowalert-chapter-1\/","title":{"rendered":"Overriding Firefox&#8217;s Window.Alert &#8211; Part 1"},"content":{"rendered":"<p>Window.alert is a native function built into Firefox &#8211; but that doesn&#8217;t mean it can&#8217;t be overridden.<\/p>\n<p>Check this out:<\/p>\n<p>Open <a href=\"http:\/\/getfirebug.com\/\">Firebug<\/a>, and get to the console.\u00a0 Then, click that little red arrow at the end of the input line so that you get the large box input on the right side of the screen.<\/p>\n<p>Type this into the input box:<\/p>\n<pre>var alert_count = 0;\r\nvar old_alert = window.alert;\r\nvar alert_max = 5;\r\nwindow.alert = function(alert_text) {\r\n\u00a0 if (alert_count &lt; alert_max) {\r\n\u00a0\u00a0\u00a0 ++alert_count;\r\n\u00a0\u00a0\u00a0 old_alert(alert_text);\r\n\u00a0 } else {\r\n\u00a0\u00a0\u00a0 console.log(\"Reached maximum alerts\");\r\n\u00a0 }\r\n}<\/pre>\n<p>Now, hit &#8220;Run&#8221; at the bottom of that input window.\u00a0 We&#8217;ve just overridden the window.alert function during runtime.<\/p>\n<p>Hit &#8220;Clear&#8221; at the bottom of the input window, and type in:<\/p>\n<pre>for (i = 0; i &lt; 10; ++i) {\r\n\u00a0 alert(i);\r\n}<\/pre>\n<p>Hit &#8220;Run&#8221;.\u00a0 Click &#8220;OK&#8221; for the first 5 alert windows, and watch as the rest of them are spewed out to the console.\u00a0 Nice.<\/p>\n<p>So, I don&#8217;t think this helps me much in creating my plug-in, but it&#8217;s interesting to see how window.alert is malliable at run-time.<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en\/NsIPromptService#alertCheck\">This seems to be a more relevant discovery<\/a> &#8211; Mozilla&#8217;s Chrome lets me create an alert popup with a checkbox using alertCheck.\u00a0 I think this is exactly what I&#8217;m looking for.<\/p>\n<p>I&#8217;ll tinker with it over the next few days, and post some code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Window.alert is a native function built into Firefox &#8211; but that doesn&#8217;t mean it can&#8217;t be overridden. Check this out: Open Firebug, and get to the console.\u00a0 Then, click that little red arrow at the end of the input line so that you get the large box input on the right side of the screen. [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[380,5,220,44,68,51,79],"tags":[207,210,211,208,213,1212,35,209,212],"class_list":["post-377","post","type-post","status-publish","format-standard","hentry","category-alertcheck-firefox-extensions-technology","category-computer-science","category-firefox-extensions","category-internet","category-javascript","category-security","category-technology","tag-alert","tag-alertcheck","tag-chrome","tag-dos","tag-extension","tag-javascript","tag-mozilla","tag-override","tag-windowalert"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prmTy-65","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/comments?post=377"}],"version-history":[{"count":5,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/377\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/377\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/media?parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/categories?post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/tags?post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}