Open a new window automatically after a certain number of seconds

I would like a suggestion on how I can create a Source page that automatically opens another page in a new window (in this case a store) after 15 seconds.

In practice now the page contains some buttons that open other pages, for example if 15 seconds pass (it would be nice to also insert and display a countdown), the store should automatically open in another window.

I don’t think it’s difficult, but unfortunately I’m out of ideas…

Thank you

solved, in case anyone needs it:

<p>Accesso in <span id="seconds">15</span> secondi
</p>

javascript:

var seconds = 15; // seconds for HTML
var foo; // variable for clearInterval() function

function redirect() {
    window.location.href = 'https://half-moon-by-cesar-salumi-porchettificio.sumupstore.com';
}

function updateSecs() {
    document.getElementById("seconds").innerHTML = seconds;
    seconds--;
    if (seconds == -1) {
        clearInterval(foo);
        redirect();
    }
}

function countdownTimer() {
    foo = setInterval(function () {
        updateSecs()
    }, 1000);
}

countdownTimer();
1 Like

Hi @Gianluca,

That’s a redirect though, it opens the page in the same window where the countdown timer resides.

You can also accomplish that without JavaScript like this:

<meta http-equiv="Refresh" content="15; url='https://half-moon-by-cesar-salumi-porchettificio.sumupstore.com'" />

This doesn’t show the countdown timer though.

If you need to open a new window, you can only do that using the JavaScript window.open statement, but that has been blocked for first time visitors by pretty much all browsers for years (to prevent window pop-up spam).

Cheers,
Erwin

3 Likes

I agree with @Heroic_Nonsense , the proposed solution falls short of the original brief of a page automatically opening in a new browser window after a 15 second countdown has commenced. Wherever that Javascript code was copied from, it’s old, it doesn’t do what you want, and it doesn’t conform to modern standards.

Perhaps you can provide us some more context about exactly what is needing to be accomplished here?

Popups and things opening in new windows are blocked in modern web browsers, for obvious security and annoyance reasons. They only work if initiated by the user via an event handler, like a click on a button. Even then, you can probably only spawn a new tab, rather than a whole new browser window.

Otherwise we would all be opening new windows secretly on your computer for our Bitcoin mining operations. :sunglasses:

3 Likes

Thanks to you @willwood and @Heroic_Nonsense ,
in the end yesterday, before your very valuable help, I opted for the best solution:


<meta http-equiv="refresh" content="8; URL='https://half-moon-by-cesar-salumi-porchettificio.sumupstore.com'" />

because the count of seconds made me and those who looked at it anxious, honestly.

@willwood , can I ask you something else?
I use on the Fancy Intro page, how can I make it so that at the end of the animation I can be redirected to https://half-moon-by-cesar-salumi-porchettificio.sumupstore.com?
The page where Fancy Intro resides is in a different domain from the store, it is an empty page, only the animation (which I really like), and as the animation ends I would like a redirect to the store.
It is feasible? It could be done?

Thank you

@Gianluca I think it would be feasible to have FancyIntro redirect to another page after the animation sequence has finished. But I would need to update the stack, so that there’s new code and settings to support this for you.

Looks like Joost had the option to set a browser cookie after the animation is run. So it may just be a case of me tagging-on some extra code to do the redirect when the animation sequence completes.

Thank you

sorry again @willwood , without modifying the stack, but only adding a portion of code via another stack (where it will be written by hand that when the animation ends the redirect must start by also inserting the destination URL), could it work? It would be easier to implement… if it were feasible, could you help me? Thank you for your time.

Please email me via the website if this is something you need me to add. This is code that would need to be added to the stack itself. It can’t just be added in the page inspector as you would do with custom CSS etc. Modifications to the stack itself are needed.

2 Likes

Brilliantly solved by William, thanks so much.

2 Likes