刚刚在几个网站上注意到,谷歌Chrome中显示的字体很棒.控制台显示以下错误:
来自" http://cdn.keywest.life "的字体已被跨源资源共享策略阻止加载:请求的资源上没有"Access-Control-Allow-Origin"标头.因此,不允许来源" http://www.keywest.life "访问.
我在其他几个网站上发现了完全相同的问题.通过使用以下代码替换自己的CDN引用,可以轻松解决此问题:
//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css
- 但是,这不是解决方案,只是一种解决方法.我很想知道原因和正确的解决方案.
(原因是:网站正在使用它自己的CDN,由MaxCDN提供,并且引用了字体非常棒的字体,如果你从上面提到的Bootstrapcdn资源加载相同的资源,这些字体不会被Chrome加载 - 它作品)
这是一个问题的例子(在菜单和页脚中的社交图标:http://www.keywestnight.com/fantasy-fest)
感谢您的帮助/解释!
google-chrome cdn access-control cross-domain-policy font-awesome
我想用jquery在Facebook墙上发表评论.
但我的ajax电话没有外部网址.
任何人都可以解释我们如何使用外部URL与jquery?
下面是我的代码:
var fbUrl="https://graph.facebook.com/16453004404_481759124404/comments?access_token=my_token";
$.ajax({
url: fbURL ,
data: "message="+commentdata,
type: 'POST',
success: function (resp) {
alert(resp);
},
error: function(e){
alert('Error: '+e);
}
});
Run Code Online (Sandbox Code Playgroud)
它给出了xmlhtttprequest错误.
在实际尝试使用ajax方法之前,是否有"安全"的方法来检查相同的原始策略是否适用于URL?这是我有的:
function testSameOrigin(url) {
var loc = window.location,
a = document.createElement('a');
a.href = url;
return a.hostname == loc.hostname &&
a.port == loc.port &&
a.protocol == loc.protocol;
}
Run Code Online (Sandbox Code Playgroud)
这种作品,但它是一种基于维基百科文章的手动猜测.有没有更好的方法来预先检查跨域允许?jQuery可以使用.
我读过这个设置document.domain = "example.com"
让我可以从子域访问父域.
相反的方法会相反吗?
假设我的主站点在http://example.com下运行.我想通过AJAX(GET和POST)访问的所有API函数都托管在http:// api .example.com上.
我将能够访问api.example.com
来自example.com
?
编辑:document.domain
再看一遍,我认为这不会解决问题.调用api .example.com的结果不是HTML,而是从API服务器上运行的PHP脚本输出.它可以是JSON,纯文本等,所以没有办法设置document.domain
它(因为它不是iframe).
这将是Access-Control-Allow-Origin标头如何工作的重复?,但那里的方法也不适合我.我希望我只是遗漏了一些东西.
我试图Access-Control-Allow-Origin
通过我的.NET Core Web API在我的响应中获得一个标题,我通过AJAX访问它.
我尝试过几件事.除非另有说明,否则所有内容都在Startup.cs
文件中.
方法1
根据Microsoft文档:
public void ConfigureServices(IServiceCollection services)
{
// Add database
services.AddDbContext<DbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbConnection")));
// Add the ability to use the API with JSON
services.AddCors();
// Add framework services.
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<DbContext>().Database.Migrate();
serviceScope.ServiceProvider.GetService<DbContext>().EnsureSeedData();
}
}
app.UseCors(builder => builder.WithOrigins("https://localhost:44306").AllowAnyMethod());
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
Authority = Configuration["Authentication:AzureAd:AADInstance"] + …
Run Code Online (Sandbox Code Playgroud) c# cross-domain-policy cors asp.net-core asp.net-core-webapi
Firebase如何处理跨源问题,以及基本的安全问题是什么以及如何处理?
cross-domain cross-domain-policy cors firebase firebase-security
我正在从iOS本地文件系统将html加载到UIWebView中.该HTML页面正在我们的服务器上请求json数据.
我可以获取json数据,所以问题是,UIWebView中是否没有跨域策略,或者我错过了什么?
有没有人知道about:blank
在IE document.domain
更改时在IE页面上创建iframe 的任何变通方法?
document.domain
在更改属性后,IE似乎不允许访问空/动态iframe .
例如,假设您正在动态创建iframe,然后将一些html注入其中:
// Somewhere else, some 3rd party code changes the domain
// from something.foo.com to foo.com
document.domain = 'jshell.net';
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
// In IE, we can't access the iframe's contentWindow! Access is denied.
iframe.contentWindow.document.body.style.backgroundColor = 'red';
Run Code Online (Sandbox Code Playgroud)
这是jsfiddle的实例:http://jsfiddle.net/XHkUT/
您会注意到它在FF/Webkit中运行良好,但不适用于IE.这特别令人沮丧,因为这会影响属性更改后创建的iframe document.domain
(如上例所示).
IE规则似乎是"如果您在更改后创建动态/空iframe document.domain
,则无法访问其DOM."
将iframe设置src
为about:blank
javascript:void(0)
或未javascript:""
成功.
I'm trying to access an iframe within a subdomain and get a cross domain error.
Here is the code of example.mydomain.com/iframe_test.html:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<iframe src="http://example2.mydomain.com/welcome.php" width="1000" height="600"></iframe>
<script>
$(document).ready(function()
{
setTimeout(function(){
$('#innerdiv',$('iframe').contents()).hide();
},5000);
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
And here is the code of example2.mydomain.com/welcome.php:
<?php
header("Access-Control-Allow-Origin: " . "*");
?>
<html>
<head>
</head>
<body>
<div id="innerdiv">
hello
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
When the line $('#innerdiv',$('iframe').contents()).hide() is executed, the following error occurs:
Uncaught SecurityError: Failed to …
Run Code Online (Sandbox Code Playgroud) 我有一个网站和我的REST api服务器.
我向REST服务器发出ajax post请求以创建新模型.此请求的答案将是"HTTP/1.1 201 Created"响应,标题为"Location:http://myapi.com/some/path/111 "但我收到错误消息Refused to get unsafe header "Location"
.我知道这是因为跨域访问策略和其他bla bla bla.
有谁知道如何解决它?也许我必须在响应中添加"Access-Controll-Allow-SOMETHINGHERE"标题?
UPD:
网站URL http://www.mydomain.com/
原始URI是http://api.mydomain.com/model/,新的位置URI是http://api.mydomain.com/model/211
原始URI用于ajax POST请求,该请求使用新的Location头进行响应.
javascript ×6
ajax ×3
cross-domain ×3
cors ×2
iframe ×2
jquery ×2
asp.net-core ×1
c# ×1
cdn ×1
dom ×1
firebase ×1
font-awesome ×1
ios ×1
php ×1
uiwebview ×1