In an AJAX action, I want to open a new window.
problem: the code below does not work : I see the 2 alerts, but
‘window.open’ does not open a new window.
controller :
def test1
render(:update){ |page|
page << “alert(‘before’)”
page << “window.open(‘http://www.google.com’);” <<— HAS NO
EFFECT
page << “alert(‘after’)”
}
end
view :
<%= link_to_remote “open a new window with RJS”, :url => {:action =>
‘test1’} %>
In an AJAX action, I want to open a new window.
problem: the code below does not work : I see the 2 alerts, but
‘window.open’ does not open a new window.
Ditto on Firebug.
Probably a popup blocker is preventing the window from opening. I’m
not sure how to work around that. Try disabling your popup blocker to
verify that is the problem.
Note that their javascript is sort of… lame. The trick of opening a
window and seeing if it is set makes sense, but they always close the
window’s object, which will likely fail. You probably want to move
that into the ‘if the window opened’ code only.
If you are doing this trick, I’d highly recommend only doing it once
then storing it on the session or something. Having a small window
pop up on every page hit will likely drive your users insane, and
having the pop-up window thing appear constantly will likely do the
same.