浏览器跨域问题解决方案

本文探讨了浏览器的同源策略限制以及针对此问题的跨域解决方案,包括使用代理和直接Ajax请求等方法,适用于前端开发者解决问题。

浏览器跨域问题解决方案

参考:
https://developer.yahoo.com/javascript/howto-proxy.html?guccounter=1
http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html

直接使用ajax

clt_ip_temp.html:1 Failed to load http://127.0.0.1:8010/adverter/js: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

方法二:

    var ifoo = '<script src="http://127.0.0.1:8010/adverter/js"><\/script>';
    document.write(ifoo);

提示:

clt_ip_temp.html:88 A parser-blocking, cross site (i.e. different eTLD+1) script, http://127.0.0.1:8010/adverter/js, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details.

20180822:
in Opera
window.top.location=’//’

async_usersync.html:4 GET https://ads.stickyadstv.com/user-registering?dataProviderId=593&userId=91bjRc6Q1FS50E5 0 ()
AN_async_load @ async_usersync.html:4
(anonymous) @ async_usersync?cbfn=AN_async_load:1
window.top.location.href='//baidu.com'
VM1811:1 Unsafe JavaScript attempt to initiate navigation for frame with URL 'https://www.fakenamegenerator.com/' from frame with URL 'https://www.fakenamegenerator.com/'. The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.

(anonymous) @ VM1811:1
VM1811:1 Uncaught DOMException: Failed to set the 'href' property on 'Location': The current window does not have permission to navigate the target frame to '//baidu.com'.
    at <anonymous>:1:25
(anonymous) @ VM1811:1
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值