skip to Main Content

I am trying to embed this html snipped into my google sites website so that it redirects users to my app. For some reason, it is not working, however, I added a button that does work. Why would the button work but not the auto-redirect?

<!DOCTYPE html>
<html>
<head>
  <title>Open Custom URI Immediately</title>
  <script>
    window.onload = function() {
      // Define the custom URI you want to open
      var customUri = "striperedirect://";

      // Open the custom URI immediately
      window.location.href = customUri;
    };
  </script>
</head>
<body>
  <h1>Welcome to my Google Sites page!</h1>
  <p>This page will automatically open a custom URI immediately after it loads.</p>
</body>
</html>

Button(working)

<html>
<head>
  <title>Open URI on Button Click</title>
</head>
<body>
  <button onclick="openURI()">Open URI</button>

  <script type="text/javascript">
    function openURI() {
      window.open("striperedirect://"); // Replace with your desired URI
    }
  </script>
</body>
</html>

2

Answers


  1. I got it working with this HTML code:

    <html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <h1>Welcome!</h1>
        <p>This is a test page</p>
    </body>
    <script type="text/javascript">
    window.onload = function() {
        window.location.href = "https://www.google.com";
    };
    </script>
    </html>
    

    I was able to test this code by saving it in a file, and opening that file in a browser.

    I needed to add the https:// prefix to the URL in order to make it work. (That is, in the line window.location.href = "https://www.google.com".)

    I mention this because it might work for you after adding the http:// or https:// prefix. It’s one of the few noticeable differences that caught my attention.

    I hope this helps.

    Login or Signup to reply.
  2. You actually don’t need javascript here. A meta tag can handle this for you.

    <meta http-equiv="refresh" content="0; url=http://your-website.com/" />
    

    If you want to redirect three seconds later, just replace 0 with 3.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search