0

I am trying to redirect a page in JavaScript using a variable base_url. The issue is page redirects to the wrong URL rather than the one I want to redirect to.

The script is running on this page http://www.example.com/account

In my JS code, I have:

base_url = 'www.example.com';

window.location.href = base_url + '/payment';

How can I figure out how to send users to www.example.com/payment rather than http://www.example.com/www.example.com/payment?

I don't understand why my code is pre-pending the domain name in the URL? How can I solve this issue? Any ideas?

EDIT

OK guys, I changed my base url with

base_url = '//www.domainhole.com';

I am not sure whether the page will serve on http or https therefore I used protocol-relative URL.

But why without using scheme it makes wrong url?

3
  • What happens if you change it to base_url = 'http://www.example.com';? Commented Jul 18, 2018 at 18:06
  • Try using this window.location.replace = base_url + '/payment'; Commented Jul 18, 2018 at 18:16
  • no, it loses history Commented Jul 18, 2018 at 18:17

1 Answer 1

3

Include a protocol in your base_url: base_url = 'https://www.example.com';

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.