how to redirect the hyperlink in a new tab or(new window) when clicked?
here is the step: 1.when a user click a 'a' tag 2.prevent Default 'a' event(before link to a new url,we need to do sth) 3.if the user login,do nothing. 4.if not login, redirect the hyperlink to 开发者_运维问答a login page.
the question is how to keep the orgin url and after do so judgement,and redirect the hyperlink to the url saved before?
i use window.open(url),but the chrome browser will block the action.
here is the code
E.on(selector,'click',function(e){
e.preventDefault();
var href = this.href;//save the url
//send ajax
var tag = 999919047;
S.io.getScript("setTag.do?tag="+tag,function(data){
if(data.code==0){
window.open(href);
}
else
{
hrefStr = "login.jhtml?f=top&redirectURL=http%3A%2F%2Ftemai.html";
window.location.href=hrefStr;
}
});
});
thank you very much. ^_^
Try using target="_blank" in the anchor tag. This will open the link in a new tab or window depending on the browser settings
精彩评论