window.location美元.使用IE时,origin给出了错误的值
$window.location.origin gives wrong value when using IE
$window.location.origin
在IE上返回错误的值
例子origin属性返回URL的协议、主机名和端口号。
url: http://localhost: 8080/产品/搜索
Chrome:$window.location.origin
返回http://localhost:8080
即:$window.location.origin
返回http://localhost:8080/products/search
我如何在IE上有正确的值?
您可能还需要端口号。如果是这样,你可以使用这个填充
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//"
+ window.location.hostname
+ (window.location.port ? ':' + window.location.port : '');
}
这个填充已经是Modernizr的一部分。
问题(像往常一样)是IE没有window.location.origin
可以这样写:
var root = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
或者你可以在你的javascript上面加上这段代码这样你就不用担心了
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
相关文章:
- 如何解决Access Control Allow Origin错误
- JSONP跨原点错误'不存在Access Control Allow Origin标头'
- Jquery以使用WCF.错误:XMLHttpRequest无法加载Origin.访问控制允许Origin不允许null
- 为什么我会收到错误'Access Control Allow Origin不允许'在我使用setRequ
- 错误:“Origin null 不允许由 Access-Control-Allow-Origin 使用 dataType
- No 'Access-Control-Allow-Origin'请求的资源上存在标头'错误
- Express.js post request "Origin null是不允许的"错误
- 一直得到No 'Access-Control-Allow-Origin'XMLHttpRequest错误
- 删除youtube iframe api控制台错误的方法-“阻塞了一个带有origin..的帧”;在chrome控制台
- 选项请求成功,但仍然得到Access-Control-Allow-Origin错误
- 如何解决错误"Access-Control-Allow-Origin"从javascript
- XMLHttpRequest.send()导致Access-Control-Allow-Origin错误
- 自动完成API错误:No 'Access-Control-Allow-Origin'标头存在于请求的资源
- HTTP请求时出现Access-Control-Allow-Origin错误
- AWS S3文件上传,获取No 'Access-Control-Allow-Origin'错误
- 从错误的原点进行Div变换;忽视transform-origin
- Access-Control-Allow-Origin错误不允许使用Ajax将表单发送到不同的服务器
- 如何检测ajax错误是Access Control Allow Origin还是文件实际丢失
- Access-Control-Allow-Origin'或解析错误
- window.location美元.使用IE时,origin给出了错误的值