是否可以停止重定向到另一个链接页面? [英] Is it possible to stop redirection to another link page?
问题描述
我已经搜索了很多,但似乎这不起作用。
I have already searched a lot, but it seems this can't work.
在程序中,有一个jquery ready函数可以使click事件重定向。
At the program, there is a jquery ready function to make the click event redirect.
if($.isFunction(link.attr('onclick'))){link.click();return false;}
else{document.location.href=link.attr('href');}
所以在超链接中,有2个事件可以使此页面重定向到新页面,一个是< a href =aaa> Link1< / a>
另一个是onclick事件(抱歉,我仍然感到困惑,首先执行)。
so in the hyperlink, there are 2 events can make this page redirect to new page, one is <a href="aaa">Link1</a>
the other is onclick event (sorry I am still confused which executes first).
不幸的是,我无法删除jquery代码..所以我只能添加新的代码。
Unfortunately, I can't delete the jquery code..so I can only append new code.
我想打开一个新窗口而不是重定向,但是如何停止重定向动作呢?
I want to open anew window instead of redirecting, but how can I stop redirecting the action?
推荐答案
我不明白,只附加新代码是什么意思?如果这意味着您无法更改onclick处理程序或上述代码,则解决方案如下所示:
I don't understand, what do you mean by "only append new code"? If that means that you cant change the onclick handler or the above code, the solution goes like this:
标识要为其更改行为的链接,删除onclick处理程序。
Identify the link, for which you wish to change the behavior, remove the onclick handler.
$(".someClass a").unbind('click');
添加新的onclick处理程序:
Add new onclick handler:
$('.someclass a').bind(function(e){
var url = $(e.target).attr('href');
window.open(url, 'width=200');
}));
当页面加载和你想要覆盖的所有链接都在DOM中时,应该执行所有这些代码。
All this code should be executed when page loads and all the links you wish to override are in DOM.
$(document).ready(function(){
//unbind links ...
$(".someClass a").unbind('click');
//bind with changed onclick handler
$('.someclass a').bind(function(e){
var url = $(e.target).attr('href');
window.open(url, 'width=200');
}));
});
这篇关于是否可以停止重定向到另一个链接页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!