1

I'm trying this with no luck:

{{ link_to('javascript:void;', 'Print', array('onClick' => 'iPrint(docIframe)', 'style' => 'float:right; position:relative; top:-410px;')) }}
KinsDotNet
  • 1,500
  • 5
  • 25
  • 53

1 Answers1

1

It's not working because the link_to function prepends the site root to javascript:void. You could work around this by adding # in front of javascript:void, causing the link_to function to treat your link as a valid URL so that it doesn't need to add the site root:

{{ link_to('#javascript:void;', 'Print', array('onClick' => 'iPrint(docIframe)', 'style' => 'float:right; position:relative; top:-410px;')) }}

This will successfully execute the javascript and trigger onClick, though note it will also show the # link in the browser's location box.

In a case like this, it would be better perhaps to skip Blade altogether and just use <a href...>.

It should also be mentioned that using javascript:void(0) is not always the best idea; see the discussion at https://stackoverflow.com/a/1293130/4043861.

Community
  • 1
  • 1
damiani
  • 7,071
  • 2
  • 23
  • 24