auto close url

Rosy14
Tera Guru

Hi,

I have a button. after clicking it will download a iCalenter type file. then it is going to another url. I want to autoclose that redirection. tried not working.

HTML:

<a href = "{{data.addToCalender}}" target="_blank" onclick="c.close()">
<button class="btn btn-primary action-btn pull-right">
Add to calendar
</button></a>

client Script:

c = this;
c.close = function(){
setTimeout(window.close,1000);
}

3 REPLIES 3

tanuj_agarwal
Tera Contributor

Hi @Rosy14 

It seems like you're trying to close the window after clicking on a button, but it's not working as expected. 

Firstly, ensure that your HTML markup is correct. It's better not to nest a button inside an anchor tag (<a>). Instead, you can directly attach the onclick event to the button itself.

Here's how you can modify your code:

 

HTML

 

<button class="btn btn-primary action-btn pull-right" onclick="closeWindowAndRedirect('{{data.addToCalender}}')">
Add to calendar
</button>

 

Client Script

 

var c = this;

c.closeWindowAndRedirect = function(url) {
window.open(url, '_blank');
setTimeout(function() { window.close(); }, 1000);
};

 

Try this and let me know if it works.

 

Tanuj

Rosy14
Tera Guru

Still not working. noting happening after clicking the button

Hi @Rosy14 ,

Can you do a gs.info on the client side or a alert to confirm if the onclick is working correctly with the parameters passed.

Then share a snapshot with the code you have to help me debug..

 

Tanuj