开发者

Open new tab after server response with jQuery

I have a lil problem with opening new tab in the browser after server response. Here is a server code (I use Rails 3.0.5):

respond_to do |format|
    format.js { render :json => {:url => link.url}, :status => :accepted }
end

So since I use jQuery as a default JS library after AJAX call I handle server response with this script:

$('.link').bind('ajax:success',
  function(e, data, textStatus, jqXHR){
    $('#megalink').attr("href", data.url);
    $('#megalink').trigger('click');
});

where "megalink" is:

<a href="" style="color:white;" target="_blank" id="megalink">.</a>

So the problem is: After 202 server response n开发者_Python百科ew tab isn`t created. May be you know how to open url in the new tab?


Use window.open(data.url);

Hope that helps.


Hm, the _blank target should work, if you could setup a jsfiddle to show how it breaks, it'd be easier to help. Otherwise, you can just try doing:

window.open(thenewurl);


The browser popup blocker blocks opening a new window during script execution context.

Use jquery AJAX in a synchronous mode it will solve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜