T. K.

asked • 02/25/21

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

I need to redirect from my website if there are no parameters in the url with javascripthtml. (redirect with html,js)

For example, if a page on my site was example.com/page and if there were parameters on the current page (e.g. example.com/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. example.com/page.html - redirecting to - example.org/rejected)

Is there anyone who can help me? I'm still learning Javascript so this is tough for me.


T. K.

P.S. look closely at my example because some answers are doing the exact opposite of what I want it to. It redirects if there are parameters but does not is there are no parameters. I need it to redirect if there are no parameters and stay if there are parameters


1 Expert Answer


Lindsey A. answered • 03/04/21

4.9 (134)

Master's Degree in Web Design, Including CSS / HTML / JS

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.