Professional Documents
Culture Documents
http://www.javascriptkit.com/howto/newtech2.shtml
<a href="whatever.htm" onClick="window.print();return false"><img src="print.gif"></a> Return false cancels the default action, which is to link to "whatever.htm". By cancelling the default action, the image above becomes exclusively a button that prints a document, which is what we want in this case. (Note: there is another similar way to achieve the same thing, which is to create a false (non existence) anchor link, and taking out the return false part.) 2nd method: Using a "JavaScript url" in an image link: Another way to accomplish the exact same task as above is to use a "JavaScript url". A JavaScript url is a special kind of url that executes a command, instead of loading the specified url. Lets see an example of such before explaining what exactly it is:
<a href="javascript:window.print()"><img src="print.gif"></a> The part in red is a JavaScript method, but look at where it is inserted-in place of the target link! The syntax for all JavaScript urls are the same: javascript:script codes here Any JavaScript code can be inserted inside to carry out an action when a link is clicked, thus the name, JavaScript url! For example, the below will pop up an alert box when the link is clicked: Click here <a href="javascript:alert('hi there!')">Click here</a>
1 de 1
3/9/2014 10:07 PM