zoukankan      html  css  js  c++  java
  • 跨域访问,跨域调用窗口

    目的在与调用不同(子)域名的通用登录窗口,并实现跨域操作
    ##########主页#######################

    var getHost = function () { var host = "null"; var url = window.location.href; var regex = /.*://([^/|:]*).*/; var match = url.match(regex); if (typeof match != "undefined" && null != match) { host = match[1]; } if (typeof host != "undefined" && null != host) { var strAry = host.split("."); if (strAry.length > 1) { host = strAry[strAry.length - 2] + "." + strAry[strAry.length - 1]; } } return host;// host格式 '.xxxx.com' } function IsTestUrl(documentStr) { var v_domain = documentStr; if (/tgxrc|localhost|d:/gi.test(v_domain)) {//是否本地测试域名 return ".txxxx.com"; } else return ".xxxx.com"; } function loginForm() { layer.closeAll(); document.domain = getHost(); layer.open({ type: 2, shade: 0.3, shadeClose: true, fix: false, title: "企业登录", area: ['600px', '380px'], content: "http://pass" + IsTestUrl(document.domain) + "/vip/login", //登录页面地址 调用其他域名的登录地址 close: function (index) { layer.close(index); } }); } function loginLayerOp() { layer.closeAll(); showThisForm(); } var c_cna_Sel_pk = true; function showThisForm() { document.domain = "share" + IsTestUrl(document.domain); layer.open({ type: 2, shade: 0.3, fix: false, title: false, shadeClose: true, area: ['600px', '450px'], content: '/Subject2017/MiddleSenior/PartialShowInfo', close: function (index) { layer.close(index); } }); }

    ################局部视图页##################

    <script type="text/javascript">
    var v_domain = document.domain;
    if (/txxxx|localhost|d:/gi.test(v_domain)) {//是否本地测试域名
    v_domain = ".txxxx.com";
    }
    else
    v_domain = ".xxxx.com";

    function loginLayerOp(index) {

    layer.closeAll();
    }
    $("#sureLoginBtn").click(function () {
    document.domain = "share" + v_domain;
    // layer.closeAll();
    parent.loginForm();
    });
    </script>

     

    需要重新 将document.domain 设置回主页所在域名。否则parent将不可用

  • 相关阅读:
    【BZOJ】2237: [NCPC2009]Flight Planning
    【BZOJ】2216: [Poi2011]Lightning Conductor
    实用工具/学习网站
    windows下MongoDB的安装及配置
    Error:(4, 25) java: 找不到符号符号:类 xxx位置:程序包 xxx.xxx
    java实现经典排序算法
    Java使用RSA加密解密签名及校验
    Java实现数字签名
    The bean 'xxx' could not be injected as a 'com.zp.demo.service.xxx' because it is a JDK dynamic proxy that implements: com.zp.demo.service.ReportService
    springboot+shiro 跨域解决(OPTIONS)
  • 原文地址:https://www.cnblogs.com/NotEnough/p/7560480.html
Copyright © 2011-2022 走看看