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
I got it working with this HTML code:
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 linewindow.location.href = "https://www.google.com"
.)I mention this because it might work for you after adding the
http://
orhttps://
prefix. It’s one of the few noticeable differences that caught my attention.I hope this helps.
You actually don’t need javascript here. A meta tag can handle this for you.
If you want to redirect three seconds later, just replace 0 with 3.