Skip to content

Instantly share code, notes, and snippets.

@h4kun4matata
Created September 5, 2017 00:11
Show Gist options
  • Select an option

  • Save h4kun4matata/e8c3fa7b8e9370748737fcd7f6b2ee1b to your computer and use it in GitHub Desktop.

Select an option

Save h4kun4matata/e8c3fa7b8e9370748737fcd7f6b2ee1b to your computer and use it in GitHub Desktop.
<script>
var popup = {
open : function()
{
this.popupWindow = window.open('http://www.facebook.com');
return setTimeout(function() {
popup.close();
}, 3000);
},
close : function()
{
this.popupWindow.close();
this.timeout = this.loop();
},
loop : function()
{
var self = this;
// On first run open popup immediately, or wait 10 seconds and restart
// the loop
if (self.active === true)
{
return setTimeout(function() {
self.timeout = self.open();
}, 5000);
}
else
{
self.active = true;
self.timeout = self.open();
}
},
clearLoop : function()
{
clearTimeout(this.timeout);
this.active = false;
}
};
popup.loop();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment