I have a button which navigate user to another page. (It has to be button not link). I want to open the page in new tab (or even new window!). Do I have to use JavaScript? or is there any other way! I'll appreciate your help.
Cheers.
To expand on the answers suggesting using `target="_blank" in Rails...
If you're using the button_to
helper, this is automatically wrapped in a form by Rails. It's the form
tag that needs this attribute. To get it, pass it as a value in the hash of html options, for example:
button_to t(:translated_text), foo_path(foo.id), class: 'btn btn-primary', form: {target: '_blank'}
the class:
and form:
are elements of the html_options
hash. The form:
option is special because it tell Rails you want to pass the HTML option to the form
tag, instead of the input
tag of the button itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With