0

I want to make it so that for example if I'm on myownwebsite.com when it loads I want the URL to change but not visit the link just have it say the URL I want in there for example mysecondwebsite.com is this possible?

3 Answers3

2

Your particular example isn't possible with JavaScript only. The history API does publish a method called pushState(), which allows you to change the URL displayed in the address bar, but -- like so many other JavaScript features -- it is bound by the same-origin policy. In this case, you cannot change the address to a URL that has a different origin (i.e. hostname + port number) than the currently loaded page. Otherwise, it would be way too easy for malicious websites to pose as Google, Facebook, etc.

Máté Safranka
  • 4,081
  • 1
  • 10
  • 22
0

This doesn't exactly answer your question as it is not javascript, but would a DNS CNAME record work in your case?

quote: "A Canonical Name record (abbreviated as CNAME record) is a type of resource record in the Domain Name System (DNS) used to specify that a domain name is an alias for another domain (the 'canonical' domain)."

from: https://en.wikipedia.org/wiki/CNAME_record

M3NTA7
  • 1,307
  • 1
  • 13
  • 25
0

No, it is impossible.

The browser won't authorize you to "cheat" on users.

If the URL is the second website's URL, it should show the second website's content.

What if you make the second website show the first website's content while you receive a certain query parameter?

Terry Wei
  • 1,521
  • 8
  • 16