spe*_*ked 31 javascript jquery
我无法控制的页面上生成的代码包含警报.是否有jQuery或其他方法来禁用alert()工作?
我想要禁用/修改的javascript是:
function fndropdownurl(val)
1317 { var target_url
1318 target_url = document.getElementById(val).value;
1319 if (target_url == 0)
1320 {
1321 alert("Please Select from DropDown")
1322 }
1323 else
1324 {
1325 window.open(target_url);
1326 return;
1327 }
1328 }
Run Code Online (Sandbox Code Playgroud)
我想在第1321行禁用警报
谢谢
And*_*ore 89
只需alert使用您自己的空函数覆盖即可.
window.alert = function() {};
// or simply
alert = function() {};
Run Code Online (Sandbox Code Playgroud)
joa*_*oar 14
这适用于Chrome和其他具有该console.log功能的浏览器.
window.alert = function ( text ) { console.log( 'tried to alert: ' + text ); return true; };
alert( new Date() );
// tried to alert: Wed Dec 08 2010 14:58:28 GMT+0100 (W. Europe Standard Time)
Run Code Online (Sandbox Code Playgroud)
试试这个:
alert("test");
alert = function(){};
alert("test");
Run Code Online (Sandbox Code Playgroud)
第二行分配一个新的空白函数来提醒,同时不会破坏它是一个函数的事实.请参阅:http://jsfiddle.net/9MHzL/