zoukankan      html  css  js  c++  java
  • 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和其他的形式都会被提示阻止。这里必须同步执行。

  • 相关阅读:
    流程控制之while循环
    流程控制之if判断
    基本运算符
    格式化输出的三种方式
    Python与用户交互
    解压缩
    布尔类型
    字典类型
    列表类型
    字符串类型
  • 原文地址:https://www.cnblogs.com/kudosharry/p/4040837.html
Copyright © 2011-2022 走看看