网址跳转后显示跳转前的网址技巧
'location.replace('https://www.ygbxheb.cn/index1.html');'改为'location.href = 'https://www.ygbxheb.cn/index1.html');'后,网址跳转后,浏览器地址栏中的网址还是跳转后的新网址,如何让它跳转后显示跳转前的网址,网页内容是跳转后的内容,网址显示跳转前的网址内容:要实现网址跳转后显示跳转前的网址,可以使用以下方法:\n\n1. 使用location.replace()方法进行网址跳转,并在跳转前保存跳转前的网址到浏览器的历史记录中:\n\njavascript\nvar oldUrl = location.href;\nlocation.replace(\'https:\/\/www.ygbxheb.cn\/index1.html\');\nhistory.replaceState(null, null, oldUrl);\n\n\n2. 使用location.href进行网址跳转,但在跳转后立即使用history.replaceState()方法将跳转前的网址替换为跳转后的网址:\n\njavascript\nvar oldUrl = location.href;\nlocation.href = \'https:\/\/www.ygbxheb.cn\/index1.html\');\nhistory.replaceState(null, null, oldUrl);\n\n\n这样,网址跳转后,浏览器地址栏中的网址将显示跳转前的网址,而网页内容则是跳转后的内容。
原文地址: https://www.cveoy.top/t/topic/pSkS 著作权归作者所有。请勿转载和采集!