I am trying to have a button that when clicked
#1- Opens a new tab to an external website
#2- Waits 7 seconds
#3- Hides box2 and shows box3
I have been able to get #2 and #3 to work perfectly. However, I am stumped with getting the first part to work correctly. I have searched over the forums here and have found people talking about slightly similar issues but I haven’t found a fix. Is there a way to make this work? And I have looked at the API and documentation just not certain if this is possible or I’m just looking at something wrong. Much thanks!
export function button7_click(event) {
// Delays 7 seconds, Hides Box 2 and Reveals Box 3
setTimeout( function () {
$w( “#box2” ).hide();
$w( “#box3” ).show();
}, 7000 );
}
Hello Chad,
i think this won’t be possible, because you will directly redirect to the new page. That means, after pressing the button, you can not stay on the current webpage, you will be redirected immediately.
What you can do is…
- wait 7sec.
- close boxes
- redirect to new url
Chad,
Here it is:
export function button7_click(event) {
setTimeout( function () {
$w( “#box2” ).hide();
$w( “#box3” ).show();
}, 7000 );
}
$w.onReady( function () {
$w( “#button7” ).link = "http://insert YourWebsiteHere .com" ;
$w( “#button7” ).target = “_blank” ;
});
Best of luck!
Nathan
So I guess I am having a weird problem here. I am unable to get this to work on the buttons I had previously created. However, if I create a new button I can get the external link to launch in a new tab. This introduces a new problem of breaking the show/hide of the boxes. I have created a new page to test this on again to factor out other things causing issues.
If anyone has any ideas as to why I am only able to perform one action and not both launching a new tab and showing/hiding boxes I’d really appreciate it! I have linked my test page below and also provided the updated code being used.
howtotech. us/free-download-template
Button names have changed due to troubleshooting and scaling the buttons and what not down.
export function button3_click(event) {
setTimeout( function () {
$w( “#box2” ).hide();
}, 7000 );
}
$w.onReady( function () {
$w( ‘#box3’ ).hide();
$w( “#button3” ).link = “http://youtube .com” ;
$w( “#button3” ).target = “_blank” ;
});
I’m not sure exactly what you are trying to accomplish. You can have a box hide and open another link with the same click of the button. See the example I made both the new tab is opened and the box disappears after clicking the button. https://sukkahartwork.wixsite.com/mysite-4/test