如果url中没有参数则重定向到其他页面,否则停留在当前页面

Redirect to other page if there are no parameters in url, otherwise stay at current page

如果 url 和 javascript 中没有 no 参数,我需要从我的网站重定向, html。 (重定向 html,js)

例如,如果我网站上的某个页面被 www.tamoghnak.tk/page and if there were parameters on the current page (e.g. www.tamoghnak.tk/page.html?code=J0eXAiOij ) then the page should stay at the current page . If there are no parameters on the current page then it should redirect to another page. (e.g. www.tamoghnak.tk/page.html - redirecting to - www.tamoghnak.tk/拒绝)


答案: - - 下面是

<script>
const urlContainParams = window.location.search.length === 0;
if (urlContainParams) window.location.href = 'https://www.tamoghnak.tk/rejected';
</script>

感谢Eduardo Sousa

你可以这样做

const urlContainParams = window.location.search.length === 0;
if (urlContainParams) window.location.href = 'example.org/rejected';