将 HREF 值的特定筛选选择的所有实例转换为另一个值的脚本
Script that converts all instances of a specific filtered selection of HREF values to another value
由于 Firefox 无法在新选项卡中打开链接,如果它们具有 HREF 标记转移到函数,也许可以使用脚本来转换它们;即实际的 HREF。
我可以看到 foo 做了什么;
function foo(x) { self.location.href = 'page.asp?ID=' + x }
所以我需要更改所有实例;
<a href="javascript:foo(12354)">
至;
<a href="page.asp?ID=12354">
其中 12354 是变量,唯一需要修改的 HREF 标记是调用函数 foo 的标记?
类似;
var anchors = document.querySelectorAll('a');
for(var i=0;i<anchors.length;i++)
{
if(anchors[i].href includes 'foo' then
{
val1 = get the value within the parenthesis; i.e. 12354
anchors[i].href = "page.asp?ID=" + val1
}
}
枚举 href
属性中有 foo
文本的链接,提取 id 并分配一个新值:
[].forEach.call(document.querySelectorAll('a[href^="javascript:foo"]'), function(a) {
var id = a.href.match(/\d+/)[0];
a.setAttribute('href', 'page.asp?ID=' + id);
});
由于 Firefox 无法在新选项卡中打开链接,如果它们具有 HREF 标记转移到函数,也许可以使用脚本来转换它们;即实际的 HREF。
我可以看到 foo 做了什么;
function foo(x) { self.location.href = 'page.asp?ID=' + x }
所以我需要更改所有实例;
<a href="javascript:foo(12354)">
至;
<a href="page.asp?ID=12354">
其中 12354 是变量,唯一需要修改的 HREF 标记是调用函数 foo 的标记?
类似;
var anchors = document.querySelectorAll('a');
for(var i=0;i<anchors.length;i++)
{
if(anchors[i].href includes 'foo' then
{
val1 = get the value within the parenthesis; i.e. 12354
anchors[i].href = "page.asp?ID=" + val1
}
}
枚举 href
属性中有 foo
文本的链接,提取 id 并分配一个新值:
[].forEach.call(document.querySelectorAll('a[href^="javascript:foo"]'), function(a) {
var id = a.href.match(/\d+/)[0];
a.setAttribute('href', 'page.asp?ID=' + id);
});