javascript - JavaScript:如何在同一域中从“example.com/page1”重定向到“example.com/page2”?
问题描述
我想要一个使用 JavaScript 重定向https://www.example.com/collections/all?sort_by=best-selling
到https://www.example.com/collections/all
同一个域名的 JavaScript 代码。
解决方案
如果您使用window.location.assign("yoururl")
它会导致加载新文档。如果您使用window.location.replace("yoururl")
它,它将替换当前文档并用该 URL 替换当前历史记录,这样您就无法返回上一个加载的文档。
参考:https ://developer.mozilla.org/fr/docs/Web/API/Location/assign 参考:https ://developer.mozilla.org/fr/docs/Web/API/Location/replace
推荐阅读
- flutter - 颤振:如何删除 mapbox 标志
- python - for 循环中的 if 语句仅在条件标记时执行最后一次迭代
- php - PHP - 多个 curl 请求 curl_multi 速度优化
- godot - 如何在 Godot 中检测 kinematicbody 2d(player) 节点和rigidbody2d 节点(mob) 之间的碰撞
- nginx - 无法在 nginx 中访问除“/”以外的 URL
- design-patterns - 解耦核心和辅助功能的设计模式
- python-3.x - Python3 networkx plane_layout 节点位置和图形大小
- python - python pandas:如何为折线图切换x轴和y轴
- flutter - 如何根据 Flutter 中另一个文本字段的值自动设置文本字段的值?
- amazon-web-services - 尝试从 VPC 内的 S3 将数据读入 AWS SageMaker 时出错