简体   繁体   English

Javascript相同来源政策和Google Crome控制台

[英]Javascript same origin policy and Google crome console

Does same origin policy apply when you execute javascript in google crome console utility that came from internet domain locally. 当您在本地来自Internet域的google crome控制台实用程序中执行javascript时,是否适用相同的来源政策? for example what happens if I do this in console. 例如,如果我在控制台中执行此操作会发生什么。

//from facebook.com
alert('javascript')
// we can xhr as well here

Anything you execute from the Chrome console is executed in the context of the web page that you opened it from. 您从Chrome控制台执行的所有操作都会在您从中打开网页的上下文中执行。 So if you try to perform an AJAX call to a different domain from that page, it will be restricted by the same-origin policy. 因此,如果您尝试对该页面的其他域执行AJAX调用,则该域将受到同源策略的限制。

I opened the console here on SO, and typed: 我在SO上打开了控制台,然后输入:

$.get('http://dev.bridgebase.com/barmar_test/test.html', function(x) {console.log(x);})

and I got the error: 我得到了错误:

XMLHttpRequest cannot load http://dev.bridgebase.com/barmar_test/test.html?_=1481190195362 . XMLHttpRequest无法加载http://dev.bridgebase.com/barmar_test/test.html?_=1481190195362 No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://stackoverflow.com ' is therefore not allowed access. 因此,不允许访问源“ http://stackoverflow.com ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM