简体   繁体   中英

Change website when redirecting from another page

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 !

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"
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM