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

Javascript 若url中并没有参数,则重定向到其他页面,否则停留在当前页面,javascript,html,redirect,parameters,parameter-passing,Javascript,Html,Redirect,Parameters,Parameter Passing,如果url中有javascript,html的参数,我需要从我的网站重定向。(使用html、js重定向) 例如,如果我网站上的一个页面是/page,并且当前页面上有参数(例如/page.html?code=J0eXAiOij),那么该页面应该保持在当前页面上。如果当前页上没有参数,则应重定向到另一页。(例如/page.html-重定向到-/拒绝) 回答:-下面是哪个 <script> const urlContainParams = window.location.search.l

如果url中有javascripthtml的参数,我需要从我的网站重定向。(使用html、js重定向)

例如,如果我网站上的一个页面是/page,并且当前页面上有参数(例如/page.html?code=J0eXAiOij),那么该页面应该保持在当前页面上。如果当前页上没有参数,则应重定向到另一页。(例如/page.html-重定向到-/拒绝)


回答:-下面是哪个

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

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

谢谢你

您可以通过这样做来实现这一点

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