We have a simple outputLink whose only function is to print the current page. This is working fine in Firefox and Chrome, but in IE8 it opens the Print dialog box and then promptly crashes.

<apex:outputLink value="#" styleClass="navImageCustom printImage" title="Print" onclick="window.print();"/>

In IE9 it also opens the Print dialog, but the page refreshes and gives the error "The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores.”"

I tried adding a "return false;" to the onclick but the crash remains. What's the easiest way to print a Visualforce page?

Edit: <div class="navImageCustom printImage" onclick="window.print(); return false;"></div> also fails.

  • forceguru.blogspot.in/2012/12/… This is a good blog that may be helpful.Also may be you may tweak some code . Also i think not a bad idea if you could replace outputLink with command link and try once to see any luck Commented Dec 20, 2012 at 19:17
  • 1
    When I copy paste your code i see no clickable link. Is there a copy paste error here? should it be <apex:outputLink value="#" styleClass="navImageCustom printImage" title="Print" onclick="window.print();"> hello </apex:outputlink> ?
    – Rao
    Commented Dec 20, 2012 at 19:25
  • one of the styleClasses contains a background image loaded as a Static Resource. That's why there's something to click. I also tried with your "hello" link and it still crashed.
    – George S.
    Commented Dec 20, 2012 at 19:27
  • ah got it I tried it in IE8 as well in chrome and mozilla , I was able to print the view :/
    – Rao
    Commented Dec 20, 2012 at 19:30

1 Answer 1


The issue is that it is trying to go to a URL of window.print(); return false;, e.g., https://c.na14.visual.force.com/apex/window.print(); return false. That page doesn't exist so it is trying to give you the intermediate page where you can choose to create a VF page with that name, but the name isn't a valid page name so you get that error.

You can see the same error if you type in any invalid page name. For example, try using something with a space: https://c.na14.visual.force.com/apex/bad name.

If you want to be able to use the same basic code, I think you can just use the javascript pseudo-protocol to get around it.

Change your onclick from

onclick="window.print(); return false"


onclick="javascript:window.print(); return false"

Alternatively, you could use something like jQuery to attach an event handler and then call window.print() from the event handling JavaScript code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .