View Full Version : HIde Link in Print Page
biswajit_5
04-17-2003, 05:37 AM
HI
I want to print page which contain several links.But I want that when i take printout the link should not come.For example
In my page one text area is there and 3-4 links are there and a button is there for printing.When I am click on the link one message will going to write in the text area.And when i want to take the printout i need all should come except the links.So can u give any solution for this.
HairyTeeth
04-17-2003, 07:27 AM
Not sure how this will work, but you should be able to do it from a style sheet:
<style type="text/css">
@media print {
a{
visibility:hidden;
}
}
</style>
biswajit_5
04-17-2003, 07:54 AM
Can u explain to my previous mail as it is not cleared.Where I should include and how
HairyTeeth
04-17-2003, 09:16 AM
Sorry, I don't think I understood properly.
Do you want to print out the message in the textarea?
or
Do you want to print the whole page without the links?
biswajit_5
04-17-2003, 09:33 AM
Hi
I have attached the file.There U'll see links.When I take the print out I need the link should not come in the print out.
david7777
04-17-2003, 10:05 AM
You can use CSS to not show certain things in a printed page, but it only works in IE5.5 and up... No netscape or any other support, so its a bit useless until people start supporting it.
So the best thing to do would be to use a server side language like ASP to do it: so you would click the print button/link, then the user will be taken to a printer friendly version of the information, and the document can automatically print, then go back to the previous page... If you are interested in this approach, let me know, and i will help you out...
Bill Posters
04-17-2003, 10:17 AM
Originally posted by david7777
You can use CSS to not show certain things in a printed page, but it only works in IE5.5 and up... No netscape or any other support, so its a bit useless until people start supporting it.
Not true. Opera, Moz, Camino and NN7* all support it just fine.
(* possibly even NN6)
Can't speak for other browsers as I don't have any others installed (aside from IE which we already know supports it)
--
Fwiw, it's better to use display: none; rather than visibility: hidden; as this way the rest of the content shifts up rather than leaving blank gaps on the printed page.
HairyTeeth
04-17-2003, 10:24 AM
Since I've done it, I'll post but David7777 sugestion is probably the best idea.
<html>
<head>
<title>Untitled</title>
<script type="text/javascript" language="javascript">
<!--;
//hide links when user hits 'Print' button;
function printPage(){
var linkObj;
var numberOfLinks = 2;
var linkIndex=0;
for(i=0;i<numberOfLinks;i++){
linkIndex = (i + 1);
//if IE4x;
if(document.all && !document.getElementById){
linkObj = eval("document.all('link_'"+linkIndex+"')")
linkObj.style.visibility = "hidden";
//if Moz 1x, Netscape6,7; IE5,6;
} else if(document.getElementById){
linkObj = eval("document.getElementById('link_"+linkIndex+"')")
linkObj.style.visibility = "hidden";
}
}
self.print()
}
//show links if user cancels the print;
function showLinks(){
var linkObj;
var numberOfLinks = 2;
var linkIndex=0;
for(i=0;i<numberOfLinks;i++){
linkIndex = (i + 1);
if(document.all && !document.getElementById){
linkObj = eval("document.all('link_'"+linkIndex+"')")
linkObj.style.visibility = "visible";
} else if(document.getElementById){
linkObj = eval("document.getElementById('link_"+linkIndex+"')")
linkObj.style.visibility = "visible";
}
}
}
//-->
</script>
</head>
<body>
<form>
<textarea>Some Text</textarea>
<a href="link_1.html" id="link_1">Link One</a>
<a href="link_2.html" id="link_2">Link Two</a>
<br>
<input type="button" onclick="printPage()" value="Print" />
<input type="button" onclick="showLinks()" value="Show Links" />
</form>
</body>
</html>
See how that goes anyway.
---EDIT:
I couldn't actually print this out because my printer is on the blink, so , even though the links disappear whne I hit print, I don't know if they will disappear from the printed page
---
biswajit_5
04-17-2003, 10:31 AM
Hi
I am using IE5.5 and the code is in JSP.
Bill Posters
04-17-2003, 10:37 AM
Why complicate the matter by using javascript?
Why not just add a css class like the one I posted previously to the elements that shouldn't be printed to a print media css file and simply leave it at that?
Javascript won't always be enabled, so it's not the best way to address the issue.
It's a clever script, but it's complete overkill and will be rendered completely useless if the user has javascript disabled.
I just think that javascript is completely the wrong way to go about getting the result you want in this situation.
A print media-specific css file is by far the best and most appropriate option.
Anyway... ;)
HairyTeeth
04-17-2003, 10:45 AM
actually, i agree with you completely Bill, its there as an option thats all.
:)
david7777
04-17-2003, 11:02 AM
Originally posted by Bill Posters
Not true. Opera, Moz, Camino and NN7* all support it just fine.
(* possibly even NN6)
Can't speak for other browsers as I don't have any others installed (aside from IE which we already know supports it)
Sorry about that - i must have been missinformed :o
biswajit_5
04-17-2003, 02:10 PM
Thnks for the help
I solve my problem with thew help of the tips I got.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.