gpt4 book ai didi

javascript - 从链接中删除 JavaScript

转载 作者:行者123 更新时间:2023-11-28 02:20:56 26 4
gpt4 key购买 nike

链接代码如下:

<td class="buttonColumn">
<a href="javascript:confirmDialog('Are you sure you want go?', 'http://google.com');" class="actionButtonNew">Leave to Google</a>
</td>

<td class="buttonColumn">
<a href="javascript:confirmDialog('Are you sure you want go?', 'http://yahoo.com');" class="actionButtonNew">Leave to Yahoo</a>
</td>

页面上有多个格式完全相同的按钮也需要更改。我在想这样的事情:

var fix = document.getElementsByClassName('actionButtonNew');
for (var i=0; i<fix.length; i++) {

我不知道如何完成代码。我试过这个:

var fix = document.getElementsByClassName('actionButtonNew');
for(var i = 0; i < fix.length; i++) {
try {
var l = fix[i];
var h = fix[i].parentNode.getElementsByClassName('actionButtonNew')[0].href.replace("javascript:confirmDialog('Are you sure you want to go?',", "");
l.href = h;
} catch(e) {}
}

我知道这非常困惑和糟糕。它确实将链接更改为:'http://google.com ');

所以我想我可能走在正确的道路上。请帮我。提前致谢!

最佳答案

这里有一个想法:不要处理在某些边缘情况下必然会中断的困惑正则表达式,而是将 confirmDialog 替换为无需确认即可重定向的函数:

window.noConfirm = function(m, url) {
document.location.href = url;
}

var fix = document.getElementsByClassName('actionButtonNew');
for (var i = 0; i < fix.length; i++) {
fix[i].href = fix[i].href.replace('confirmDialog', 'noConfirm');
}

http://jsfiddle.net/AV4tB/

另一个有趣的想法:更改它调用一个立即修复链接的函数,然后触发点击:

window.fixMe = function(m, url) {
this.href = url;
}

var linksToFix = document.getElementsByClassName('actionButtonNew');
for (var i = 0; i < linksToFix.length; i++) {
window.a = linksToFix[i];
linksToFix[i].href = linksToFix[i].href.replace('confirmDialog(', 'fixMe.call(a, ');
linksToFix[i].click();
}

http://jsfiddle.net/AV4tB/1/

关于javascript - 从链接中删除 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15673865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com