0

How would I make a script that detects the current URL of the page? Here is what I want it to do:

When the script is on example.com it lets the page load normally.

When the script is on coolsite.com it replaces the content of the page with a note showing a link to example.com

How would I do that? Is there a function that detects the location of the window? I can put it in a <script> element or a separate JavaScript file.

Thank you for any help!

1 Answers1

-2
window.location.host

It's not function just check that variable value

document.body.innerHTML = `<h1>This JS runs under this host :</h1> <h2>${window.location.host}</h2>`
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254