Wednesday 15 April 2015

javascript - Bookmarklet window gets blocked if I try to do anything besides open a new window -


I am trying to write a bookmark that takes the user current site, does some parsing and ajax Request, and opens a new window with that information as an absolute

Here's what I found:

  & lt; A href = "javascript: (function ($) {var a, http, options, request, st, u; u = document. Lunation hostname; a = u.split ('.'); St = a [a. Length - 2]; path = 'http://ajax.googleapis.com/ajax/services/feed/ search: callback =? & Amp; vm; v = 1.0 & amp; q =' + st; $ .ajax ({type : 'GET', url: path, async: false, datatype: 'json', success: work (data) {var targ = data ['responseData'] ['entries'] [0] ['url']; window .open ('http: // localhost: 3000 / bmfeed? Targ =' + targ, 'menubar = 1, resizable = 1, width = 350, height = 250');}});}) (jQuery) Gt; NewWindows & lt; / A & gt;   

This finds the correct URL, but the new window has been blocked by the popup blocker.

Instead of this I just

  and   

This opens a new tab that is not created without any difference. I think the difference is that I am doing some parsing in the first example, which the browser does not like.

Is there any way to make my cake and eat it? Thanks a bunch!

I think the difference is that I'm doing some parsing the first example

No, the problem is asynchronous AJAX. The browser tries to determine whether a user's action has started a new window or not, or before deciding to block it. To open a new window without blocking it, there should be a "straight line of action" between user clicks and window opening. Async ajax breaks that straight line (synchronous ajax can work, i am not sure.)

Is there any way to make my cake and eat it?

The right solution, but what you have now, is to create a pop-over deviation on the page that is and lt; A href = "http: // localhost: 3000 / bmfeed? Targ =." Target = "_ blank" & gt; Click here to open a new window & lt; / A & gt; .

No comments:

Post a Comment