2

I use this code to override the window.alert function. The function replaces breaks by \r\n. It works fine in Firefox, but ofcourse not in IE. Im getting the error: Property or method not supported.

(function() {
 var proxied = window.alert;
 window.alert = function(txt) {
 txt = txt.replace(/<br>/g, "\r\n");
 return proxied.apply(this, arguments);
 };
})();

Please help me find the solution! Thank you

Dave Schweisguth
37.9k10 gold badges102 silver badges123 bronze badges
asked Jun 17, 2010 at 9:17
1
  • In which line do you get the error? Commented Jun 17, 2010 at 9:36

2 Answers 2

2

I would do this, in case window.alert is not a "real" function in IE:

(function() {
 var proxied = window.alert;
 window.alert = function(txt) {
 txt = txt.replace(/<br>/g, "\r\n");
 return proxied(txt);
 };
})();

Sorry, untested, Does it work?

answered Jun 17, 2010 at 9:39
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your reply. Now the error is gone, and the alert is showing, but breaks are not replaced. It's still working fine in FF though. Any ideas?
I changed the location of the code in my script and it's working fine now in both IE and FF. Thank you Victor! @Tim, I appriciate your input, and I know it's not the best way to do it, but otherwise I had to replace the alert function in my scripts to a custom made alert function. Knowing there are over 1000 scripts on my website, that's just not doable.
0

This would be fine for native JavaScript functions but is highly dangerous with methods of host objects such as window. Host objects are not subject to the normal rules of native JavaScript objects, and can (and do) behave largely as they please, often differently in different browsers. Therefore I strongly recommend not pursuing this idea for window.alert or any other host methods.

answered Jun 17, 2010 at 10:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.