跨域访问,跨域调用窗口

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

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将不可用

转载于:https://www.cnblogs.com/NotEnough/p/7560480.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值