javascript - Delaying window.open inside click event handler -
for days i've been trying (without success) open new window delay without chrome blocking of time. delay crucial task, because animation must take place before window opened , can not afford browsers block new tabs opening. here sample code:
element.on("click", function(e){ e.preventdefault(); var self = $(this), url = self[0].href; window.settimeout(function(){ window.open(url); }, 1000); });
element jquery object (anchor element more precise). have noticed have bigger success rate if pass string straight
window.open("http://example.com");
i've tried solution in explorer(no problem), chrome(problem), firefox(no problem) , opera(problem). loosing mind, because i've tried can remember. synchronous ajax calls, artificially triggering click, creating false anchor elements , artificially triggering click event. nil works fine. bonus question (in case knows how solve problem): there way phone call window.open anytime & anywhere code?
this working me in chrome http://jsbin.com/wuqopukayuwi/4/
var $element = $('#link'); $element.on('click', function () { var url= $(this).attr('href'); window.settimeout(function(){ var windowobjref = window.open(url); console.log(windowobjref); }, 2000); });
things check:
obviously, double check you've enabled popups domain in chrome (it prompts first time tries pop new window
it's because chrome expects able access window 1 time again programatically, wants declare response method variable. @ least, that's how got working...
javascript jquery settimeout window.open
No comments:
Post a Comment