Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the link_to helper to open a popup?

I just want to use link_to to open a popup. I tried something but it doesn't work:

 <%= link_to 'Create a new company',
             new_company_path,
             :popup => ['create_company', 'height=600, width=600'] %> <br/>

Any idea?

Thanks!

like image 823
Amokrane Chentir Avatar asked Mar 06 '11 03:03

Amokrane Chentir


People also ask

How to open link in popup?

Open Link in a Popup Window In order to open them in a new window, we add target="_blank" attribute to links. However to open the links in a separate popup window, we can make use of the onclick property and specifying a inline JavaScript code window.


2 Answers

Add this to your application.js.

$('a[data-popup]').on('click', function(e) { window.open($(this).attr('href')); e.preventDefault(); });

In the view, use something like:

= link_to( 'Create a new company', new_company_path, 'data-popup' => true )
like image 110
Mark Swardstrom Avatar answered Oct 19 '22 20:10

Mark Swardstrom


<%= link_to 'Create a new company',
         new_company_path, 
        :onclick=>"window.open(this.href,'create_company', 'height=600, width=600');return false;" 
%>
like image 23
Viktor Trón Avatar answered Oct 19 '22 20:10

Viktor Trón