javascript - how to remove href for "printing" html to PDF? -
i build html pages , allow user "print" html pdf, without embedding href links (because link internal server, , not want readers of pdf see these links).
in chromium, resulting pdf file embeds href links.
is possible remove hrefs via css of javascript?
i tried this:
<a class="no_print" href="javascript:printpreview()">print preview</a> <script> function printpreview() { var atags = document.getelementsbytagname('a'); var atl = atags.length; var i; (i = 0; < atl; i++) { atags[i].href = ''; } } </script>
but not work.
-- edit: after solution found, here finish illustration --
<!doctype html> <html><header> <title>x</title> <style> @media print { .no_print { display: none; } </style> <script> function printpreview() { var atags = document.getelementsbytagname('a'); var atl = atags.length; var i; (i = 0; < atl; i++) { atags[i].removeattribute("href"); } } </script> </head> <body> <a class="no_print" href="javascript:printpreview()">print preview</a> <br> <a href="http://example.com">link somewhere</a> <br> <a>anchor no link</a> <br> other text... </body> </html>
here code works fine.
<html> <a class="no_print" href="javascript:printpreview()">print preview</a> <script> function printpreview() { var atags = document.getelementsbytagname('a'); var atl = atags.length; var i; (i = 0; < atl; i++) { **atags[i].removeattribute("href");** } } </script> </html>
javascript html css
No comments:
Post a Comment