# Page \<\< "window.open('http://www.google.com');" \<\<--- HAS NO EFFECT

**URL:** <https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073>\
**Category:** Rails\
**Created:** [October 23, 2007, 6:23pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073 "2007-10-23T18:23:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 23, 2007, 6:23pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/1 "2007-10-23T18:23:27Z")

</div>

Hi all,

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](http://www.google.com)’);” \<\<— HAS NO  
EFFECT  
page \<\< “alert(‘after’)”  
}  
end

## view :

\<%= link\_to\_remote “open a new window with RJS”, :url =\> {:action =\>  
‘test1’} %\>

I’m stuck here. Any idea what’s happening?

Alain

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 23, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/2 "2007-10-23T18:28:43Z")

</div>

Go get Firebug: [http://www.getfirebug.com/](http://www.getfirebug.com/)

If you’re still stuck, post what the resulting error is.

Jason

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 23, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/3 "2007-10-23T18:42:49Z")

</div>

On 10/23/07, Alain R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> 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.

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 23, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/4 "2007-10-23T21:41:35Z")

</div>

> Probably a popup blocker is preventing the window from opening.

That was it, not that it makes sense : the Firefox popup-blocker will

- allow (open)

- but not

2ï¿½ :  
I fear a double “NO”, but I’ll ask anyway : is there

- another javascript way to _open_ a window that would go through the  
popup blocker, or
- a way to _detect_ (even indirectly) that the client’s browser has a  
popup blocker on?

Alain

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 23, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/5 "2007-10-23T21:49:11Z")

</div>

A quick Google resulted in this:

[http://www.visitor-stats.com/articles/detect-popup-blocker.php](http://www.visitor-stats.com/articles/detect-popup-blocker.php)

Looks like it might work to detect the blocker.

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.

–Michael

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 23, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/6 "2007-10-23T22:50:07Z")

</div>

> [http://www.visitor-stats.com/articles/detect-popup-blocker.php](http://www.visitor-stats.com/articles/detect-popup-blocker.php)

Thanks Michael.

There’s a much simpler way actually :

page \<\< “if (confirm(‘#{msg}’) ) {”  
page \<\< " new\_win=window.open(‘#{root\_path}’);"  
page \<\< " if (new\_win==null) {alert(‘Please disable your popup  
blocker’);}"  
page \<\< “}”

Alain

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 24, 2007, 11:45pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/7 "2007-10-24T23:45:42Z")

</div>

Instead of a real browser window, try a javascript one, like this  
[http://www.stickmanlabs.com/lightwindow](http://www.stickmanlabs.com/lightwindow)

---

<div class="post-metadata">

**Author:** ![aravet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@aravet](https://www.ruby-forum.com/u/aravet)\
**Post date:** [October 23, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/page-window-open-http-www-google-com-has-no-effect/118073/8 "2007-10-23T18:45:44Z")

</div>

have you tried:

page.call ‘window.open’, ‘[http://www.google.com](http://www.google.com)’
