a標籤的href劫持,做判斷後在跳轉

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   ar   使用   java   sp   

$.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){                            //Firefox下無法實現類比點擊                            $(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‘);
    }

Firefox下無法類比超連結點擊,使用window.open和其他的形式都會被提示阻止。這裡必須同步執行。

a標籤的href劫持,做判斷後在跳轉

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.