a标签的href劫持,做判断后在跳转

$.ajax({
               type: "POST",
               url: "/resource/logincheck",
               data: {id: id},
               success: function(data){
                    if (data.ok == 1) {
                        var href_url = dl_link[dlt];
                        if(opentype == 1){
                            window.location.href = href_url;
                        }else if(opentype == 2){
                            //火狐下无法实现模拟点击
                            $(that).attr('href',href_url);
                            $(that).attr('target','_blank');
                  setTimeout(function(){repl(that);},1000);
return true; }else{ chwTip('无法下载'); return false; } } else if (data.ok == 0) { if (data.error == 1) { chwTip('请先登录'); return false; } else if (data.error == 3) { chwTip('参数错误'); return false; } } }, async:false });

function repl(that){
        $(that).attr('href','javascript:void(0);');
        $(that).removeAttr('target');
    }

火狐下无法模拟超链接点击,使用window.open和其他的形式都会被提示阻止。这里必须同步执行。

posted on 2014-10-21 17:12  kudosharry  阅读(3584)  评论(0编辑  收藏  举报

导航