javascript - 从 URL 中删除多个参数之一并在不删除参数的情况下刷新页面但使用其他参数
问题描述
当我使用 javaScript 从 URL 中删除一个参数时,请调用:
window.location.assign(newURL);
没有参数它不会刷新页面。它什么也不做。没有参数如何刷新页面?
编辑:
我有2个参数。它会正确刷新页面并删除所有参数。但是当我在 URL 中保留其中一个参数时,它不会刷新页面。那是我的问题。
网址是:
https://thedomainsample.net/tablet/thePage.html?parameter1=388617¶meter2=true
这是我的代码:
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const firstParameter = urlParams.get('parameter1');
window.location = window.location.href.split("?")[0]+"?parameter1="+ firstParameter;
它基本上删除了第二个参数并尝试将位置设置为仅使用第一个参数的 URL。它不会刷新页面,它什么也不做。
解决方案
推荐阅读
- python - Selenium webdriver 超时后停止
- javascript - 如何向这个 js 文件添加状态构造函数?
- webpack - 带有 img 应答器的 Webpack ejs 加载器
- charts - 谷歌图表工具栏:从谷歌图表工具栏实时数据导出
- reactjs - 在 ReactJS 中使用 Fetch 进行 POST 调用(带有标头和请求正文)
- geometry - 是否有一些算法可以匹配来自候选多边形集的多边形?
- php - 如何在 PHP 中获取 Typo3 模板常量的值?
- php - 将图像转换为背景图像
- sql-server - 如何使用 SSIS 压缩文件,然后转到 Azure 数据湖(无需先导出平面文件)
- php - 在 html 视频源中需要在特定时间播放视频