window.location - 如何在codeandbox.io 中使用window.location.href?
问题描述
我想window.location.href
在工具codeandbox.io中使用。这是因为我想在发生硬页面加载的情况下进行测试。但是,我遇到了一个问题。
location.href = "http://www.google.com"
我收到此错误:
Mixed Content: The page at 'https://codesandbox.io/s/lingering-bird-nyvfi' was loaded over HTTPS, but requested an insecure resource 'http://www.google.com/'. This request has been blocked; the content must be served over HTTPS.
示例: https ://codesandbox.io/s/locationhref-usage-nyvfi (查看src/index.ts
并打开开发控制台)
如何在假的虚拟浏览器中实现模拟页面加载的能力?
解决方案
I think it may be possible once the security criteria are met; which is limiting.
- Use HTTPS (Avoid mixed content)
- Use same origin
Thus this works:
window.location.href = "https://www.codesandbox.io/docs";
推荐阅读
- vue.js - 如何在 Vue 3 组件的 setup 方法中访问 Root?
- javascript - 无法将小数添加到文本框
- javascript - 如何在 Javascript 中使用 RegEx 检测和替换字符串中的所有数组元素?
- reactjs - 如何在 apollo 客户端中模拟联合类型
- javascript - Bookshelf andWhere / orWhere 语法问题
- asp.net - WPF ManagementScope 访问被拒绝
- django - Django 多条删除记录
- android - 我在使用带有 CameraX 的 PreviewView 时遇到了问题?
- python - 有没有办法在 AWS Lambda 上使用 PyGithub
- node.js - 为 https 配置 nginx (docker) 后应用程序停止