In answer to your question (though I admit it is rather dissatisfying) qhat you wish to do is currently impossible. You cannot detect whether the cancel or print button was clicked after calling
. Your only alternative is to do something like the following to ask the user if they wish to be redirected (or if they printed but asking that would be less transparent to the user...)
if(confirm("Would you like to go back?"))
<input id="btnPrint" type="button" value="Print" onclick="return PrintAndBack();" />
Notice the extra
statements - these stop the page from refreshing after the button click if the user isn't being redirected. If the user is, then they make no difference.
Hope this helps,