views:

80

answers:

2

I need to remove the following script from my page(ASP.NET 3.5), leaving all other scripts intact:

   <script type="text/javascript">
   //<![CDATA[
      alert('Save Sucessful.');
   </script>

Should be something like $('html').children('script').remove(':contains("alert")) but this exact syntax doesn't work.

A: 

Rather than a pop-up alert, why not provide feedback with a page element (in the DOM)?

It would be there still rather than be there again.


Okay, if you cannot change it you could replace the windows.alert function, if it's executed before the code in question (usually in DOM order).

BTW, you can't just test the string (my first thought) since "Successful" should have two 'c's and the owner of that code might fix it.

But you could mute all alerts for the first 10 seconds with:

var _alert = window.alert, _alertStart=new Date().getTime();
window.alert = function() {
   var delay = (new Date().getTime()) - _alertStart;
   if (delay > 10000)
       _alert.apply( window, arguments );
};

Or, if you want to delete every inline script that contains "alert" you could use:

$('script:contains("alert")').remove();

Note that that pattern matches the script tag in which it occurs, so you could change it if it matters:

$('script:contains("al'+'ert")').remove();
Carter Galle
I agree but unfortunately can't change that part
Victor
That is exactly right, I found out that this very script tag also matches that pattern:-)
Victor
Thanks. The problem is not that this code executes before, but that if I navigate away from this page and come back TO IY via history.go(-1), i see the alert since that script is still there.
Victor
A: 

$('html').children('script:contains("alert")').remove();

Ted