I have a main page that redirects to another page called example.com
the code of the main page is:
<! DOCTYPE html>
<html>
<body>
<h2> Redirect to a Webpage </h2>
<p> The replace () method replaces the current document with a new one: </p>
<button onclick = "myFunction ()"> Replace document </button>
<script>
function myFunction () {
location.replace ("https://www.example.com")
}
</script>
</body>
</html>
example.com shows "Original Webpage" if you enter directly the code for example.com is:
<! DOCTYPE html>
<html>
<body>
<h2> Original Webpage </h2>
</body>
</html>
I want that when redirecting from the main page to example.com, example.com shows "modified page".
then you should change <h2> Original Webpage </h2> from main page before entering example.com
! I don't own example.com !
you cant change other sites' content. If it would possible, someone could redirect user to (for example) Amazon, changing its code to hijack login/password or credit card info.
Browsers have special checks to insure content of the site in address bar is genuine
Considering you own example.com.
The redirecting url could include a parameter:
location.replace("https://www.example.com/?redirected=true")
On example.com you could check if that parameter exists:
if (new URL(location.href).searchParams.get('redirected')) == 'true') {
document.querySelector('h2').textContent = "modified page"
}