我有一些java脚本只是从网站上获取一个ID并将其传递到另一个域上的另一个php脚本:
javascript正在播出:
并准备
这或多或少有效,我不得不使用以前的跨站点解决方案,现在似乎没有在firefox 23和IE10上获得荣誉。
之前的解决方案是使用类似的东西:
var isIE10 = false; //this is beacuse stupid IE10 now does not work with the window.XDomainRequest
/*@cc_on
if (/^10/.test(@_jscript_version)) {
isIE10 = true;
}
@*/
console.log(isIE10);
var isIE8 = window.XDomainRequest ? true : false;
var invocation=createCrossDomainRequest();
function createCrossDomainRequest(url, handler)
{
var request;
if ((isIE8) && (!isIE10)) //tried to hack my own isIE10 fix didnt work
{
request = new window.XDomainRequest();
}
else
{
request = new XMLHttpRequest();
}
return request;
}
function callOtherDomain()
{
if (invocation)
{
if("withCredentials" in invocation) //was taking a stab in the dark with this.
{
invocation.onload=outputResult;
invocation.open("GET", url, true);
invocation.send();
}
else if(isIE8)
{
invocation.onload = outputResult;
invocation.open("GET", url, true);
invocation.send();
}
else
{
invocation.open('GET', url, true);
invocation.onreadystatechange = handler;
invocation.send();
}
}
else
{
var text = "No Invocation TookPlace At All";
var textNode = document.createTextNode(text);
var textDiv = document.getElementById("textDiv");
textDiv.appendChild(textNode);
}
}
function handler(evtXHR)
{
if (invocation.readyState == 4)
{
if (invocation.status == 200)
{
outputResult();
}
else
{
alert("Invocation Errors Occured " + invocation.status + " state: " + invocation.readyState);
}
}
}
function outputResult()
{
var response = invocation.responseText;
//get JSON of response
var obj = JSON.parse(response);
var mtype = obj.messagetype;
var output = obj.message;
var url = obj.url;
if(mtype=="error")
{
parent.location=url;
}
else if(mtype=="warning")
{
var answer=confirm(output);
if(answer)
parent.location=url;
}
//var textDiv = document.getElementById("textDiv");
//textDiv.innerHTML += response;
}
callOtherDomain(); 所以我不确定这里发生了什么,我在控制台上遇到firefox 23错误:
Blocked loading mixed active content "http://theotherwebsite.edu"
我知道这是因为主脚本加载到https,而不是http。但它以前没有关心。我也知道这个错误会在firefox的地址栏中放置一个屏蔽,用户可以告诉它启用阻止的内容。这对我来说不是一个可接受的解决方案。另外,如果我把我愚蠢的小PHP脚本放在https下,这也是我需要的证书吗?
然后IE10无效:
SCRIPT5: Access is denied.
landing, line 64 character 421
所以我不确定我需要做些什么来让我的代码再次运行,让用户调整浏览器是不可行的,因为这是在企业范围内分布的,这是一个唠叨的屏幕,让他们知道改变他们的密码基于php文件访问的一些ldap条目,ID通过ajax从网站传递。
我正在做一些谷歌搜索但没有发现任何东西,我发现大多数是php手柄,使网站我猜CORS兼容:
<?php
header('Access-Control-Allow-Origin: *');
我最初也实现了。所以不确定要尝试什么或下一步在哪里看?它是一个简单的JSON字符串,我可以尝试这里描述的预检方法:
http://ppe.blogs.msdn.com/b/ie/archive/2012/02/09/cors-for-xhr-in-ie10.aspx
???如果我这样做,我不确定标题应该是什么样的。
我打算发布firefox 23响应标头,但它永远不会发出请求,因为它会直接阻止加载混合活动内容。所以我想我有两个问题需要解决,一个是javascript存在于https并调用http ...这可能是我在firefox中唯一的问题,而不是100%确定我是否会遇到跨站点问题。
IE10网络请求标题永远不会找到,我正在IE10中查看F12键按下区域,在网络下我单击开始捕获,然后我用xhr调用加载页面。
所以我想我在问firefox23和IE10有什么变化让我的代码不再工作了?
答案 0 :(得分:3)
Firefox 23+将阻止他们所谓的“活跃混合内容”。即:托管在从安全网页(https)请求的非安全(http)位置的内容。在此上下文中,“活动”实质上意味着不是媒体类型的所有内容(不是图像,音频或视频资源)。这是为了防止使用非安全子请求进入安全页面的中间人攻击。
有关详细信息,请参阅有关MDN的Mixed Content文章。
由于请求在连接网络之前被阻止,因此不会有任何响应标头/数据。
不确定IE10,但their documentation似乎表明他们出于同样的原因阻止了这些请求,并说:
不允许跨域,跨端口和混合协议请求。