js打开新窗口页面跳转
新窗口打开当前页面带参数
js
const openPage = () => {
// 基于当前 URL 创建
const newUrl = new URL(window.location.href);
// 添加或覆盖参数
if (ClientlD) newUrl.searchParams.set('hqid', ClientlD);
if (type) newUrl.searchParams.set('type', type);
if (storeId) newUrl.searchParams.set('storeId', storeId);
if (date) newUrl.searchParams.set('date', date);
window.open(newUrl.toString(), '_blank');
// 当前窗口打开不留下历史记录
// location.replace(newUrl.toString());
// 当前窗口打开留下历史记录
// location.href = newUrl.toString();
};新窗口打开同项目下指定页面并携带参数
js
const openPage = () => {
// 目标页面的基础路径
const basePath = '/SubModule/ShopKeeperAPP/DisplayCompliance/DisplayCompliance';
// 构造查询参数
const params = new URLSearchParams();
if(ClientlD) params.set('hqid', ClientlD);
if (type) params.set('type', type);
if (storeId) params.set('storeId', storeId);
if (date) params.set('date', date);
// 拼接完整 URL(自动带上当前域名)
const fullUrl = `${window.location.origin}${basePath}?${params.toString()}`;
// 新窗口打开
window.open(fullUrl, '_blank');
// 当前窗口打开不留下历史记录
// location.replace(fullUrl);
// 当前窗口打开留下历史记录
// location.href = fullUrl;
};新窗口打开不同项目下指定页面并传递参数
js
const openPage = () => {
// 目标地址
const baseUrl = 'https://www.baidu.com/s';
// 构造查询参数
const params = new URLSearchParams();
params.set('wd', searchKeyword || '默认值'); // 示例:百度搜索关键词
if(ClientlD) params.set('hqid', ClientlD);
if (type) params.set('type', type);
if (date) params.set('date', date);
// 拼接完整 URL 并打开
const fullUrl = `${baseUrl}?${params.toString()}`;
window.open(fullUrl, '_blank');
// 当前窗口打开不留下历史记录
// location.replace(fullUrl);
// 当前窗口打开留下历史记录
// location.href = fullUrl;
};