开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜