开发者

jquery script removal

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').remo开发者_运维技巧ve(':contains("alert")) but this exact syntax doesn't work.


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();


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜