嵌套页面iframe 内部链接跳转跨域问题

问题:如果直接在嵌套页面里面使用window.location.href='http://www.xxx.xx',会发现页面无法跳转,甚至出现跨域问题

解决:通过window.top.location.href 或者 window.parent.location.href 跳转

两者区别如下:

  1. window.parent.location 用于更改父窗口的位置。

  2. window.top.location

    • 它是对象'window'的属性。

    • 它返回窗口层次结构中最顶层窗口的位置。

    • 如果窗口没有父窗口,则top是对自身的引用(窗口=== window.top)

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
嵌套iframe跨域问题可以通过利用nginx进行解决。nginx可以作为反向代理来处理跨域请求。具体的解决方法如下: 1. 首先,在nginx的配置文件中添加以下配置: ``` location / { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; if ($request_method = 'OPTIONS') { return 204; } } ``` 这样可以在响应头中添加Access-Control-Allow-Origin字段,允许跨域请求。 2. 然后,将需要跨域页面嵌套iframe中,并将iframe的src指向nginx服务器的地址。 通过以上配置,nginx在响应头中添加Access-Control-Allow-Origin字段,允许跨域请求。这样就可以解决嵌套iframe跨域问题。\[1\]\[3\] #### 引用[.reference_title] - *1* *3* [利用Nginx解决跨域问题](https://blog.csdn.net/Kayson13/article/details/106466606)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Nginx反向代理解决iframe跨域问题](https://blog.csdn.net/banketan1026/article/details/102391169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值