views:

706

answers:

3

I have already searched a lot, but it seems this can't work.

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');}

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).

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?

+1  A: 

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:

Identify the link, for which you wish to change the behavior, remove the onclick handler.

$(".someClass a").unbind('click');

Add new onclick handler:

$('.someclass a').bind(function(e){
   var url = $(e.target).attr('href');
   window.open(url, 'width=200');
}));

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');
     }));

});
gregor
A: 

If I'm understanding correctly, that jQuery block is to only run the onclick if one exists otherwise it simulates a normal hyperlink click.

So if you want it to just open in a new window, and you can't change the jQuery an option would be to add an onclick event:

<a href="aaa" onclick="window.open(this.href);return false;">Link1</a>

This should execute as the onclick open in a new window.

McKAMEY
A: 

Thanks for all help.

I can't delete the redirect jquery funciton because policy..the previous programm will make some click or hyperlink redirect page in parent ..but some page need to be changed for open in new window.

let me explain in detail

There are two types of text link

<tr><td>first</td><td><a href="aaa">link1</a></td><td>3rd</td></tr>
<tr><td>first</td><td><a href="aaa" onclick="fun1()">link2</a></td><td>3rd</td></tr>

I neither can't understand why they write like this...but so sorry I can't change all html

I only can do is append new function ....

so if the user directly click the hyperlink text, it's easy for me, I can append target to _blank. but we alos have event function change page event user move the mouse to the record and click. also can redirect new page.

that's why this funciton....

if($.isFunction(link.attr('onclick'))){link.click();return false;} // I regard it for onclick function 
else{document.location.href=link.attr('href');} // it's for tag click..

so I can tell you there are 3 ways to change page.

  1. click the text link directly without click event funciton.

  2. click the same row of tag area.

  3. click the text link but with onclick function . that's the program as I know now....

So..before js function I can append some code to change the page event. I want to do is the parent window is same..no reload.and when click some area can open webpage in new window.