views:

82

answers:

3

Hello, I have a list of links that users can click. When a click is made, I want to increment a counter (to track how many users clicked that link) and then open the link in a new window.

Right now, in the 'show' method method, I can do all that except the "new window" thing. Is there a way to achieve this in pure rails or do I have to do put some additional javascript to launch an ajax request (for the incrementation) and then open the link in a new window?

thanks, Pierre

A: 

A simple javascript may do:

 window.open('filename.php?var=' + varvalue, 'resizable=1, scrollbars=1, left=80,top=60, width=650, min-height=400');

If you are using any jquery libraries, you can look into modals.

I do know about how to do this in Rails.

Natkeeran
A: 

Hi Pierre,

You need to use AJAX, either to return javascript from the server or just a success code, and then open in a new window from javascript.

HTTP provides no way to open a new window.

A note! Be SURE you're a tags still have hrefs pointing at the URLs for your SEO!

Good luck!

mixonic
+1  A: 

I would think the easiest solution would be to just have your link contain

target="_blank"

The window would open, go to your counter page, and get redirected to the correct page

John
sometimes the easiest is the best... thanks!
Pierre