Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Dynamic code replacement like you're suggesting might work in some cases, but it's a scary road to go down-- fragile, one wrong step and you're busted, and it quickly becomes a maintenance nightmare. </p> <p>As a commenter said, your cleaner bet is to just wrap the native <code>window.alert</code> and then do the right thing when the string you care about comes through, per the answer here: <a href="https://stackoverflow.com/questions/1729501/javascript-overriding-alert">JavaScript: Overriding alert()</a></p> <p>(Insert standard comment here about how you should get your server side people on the same page/team as you on this so you don't need to hack around your own page.)</p> <p>UPDATE: You're not asking about alert, you're asking about this problem generally. Yes, you could what others are suggesting. But if you have the original code for the function, why not just replace it entirely? If the function you want is a global function called <code>foo()</code>, you can run JS that does:</p> <pre><code>window.foo = function() { // The stuff I know is there (A) ... // Some new stuff I want to change (B) ... // More stuff I know is there (C) } </code></pre> <p>Which will throw away the original and replace it with your version. This would work reasonably well, although "monkey patching" the stuff in the page definitely comes with some maintenance headaches.</p> <p>I will definitely note here that if you can't do this for some reason and thus insist on doing textual code replacement <em>in the middle of existing functions</em>, you're abusing the language/environment for the purposes of maintainable anything, and you are truly screwed in multiple ways. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload