|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How can I print whole window without images
I want to print a window using the function window.print() but in this way it is printing whole document including iamges. I don't want to print the images in the window. How can I print whole window without images
|
|
#2
|
|||
|
|||
|
Hey Lina!. I see noone has paid any atention to your request. I'm not so great at Javascript, but I'll try to provide a solution for you. I'm not really sure that you can print a document without images. The easier way out is to write a printable version (without the images) on a separate file and place a link on the master document that references the printable version. Then in the printable you place the code:
<script> function printdoc(){ window.print(); history.back(1); } </script> <body onLoad="printdoc()"> You can also open a new window instead of using history.back(), but that is all up to you! That sould take care of the problem for now, until someone who knows more than me gives you the answer. Anibal. |
|
#3
|
||||
|
||||
|
Have you looked into using CSS to provide a Print Stylesheet?
Something as simple as img { display: none; } |
|
#4
|
|||
|
|||
|
I suppose that's even better !!
As I said, there's always someone with the right answer. Gratitud however, does not seem to be one of someone's virtudes Quote:
|
|
#5
|
||||
|
||||
|
Here's the Javascript to do it:
Code:
<html>
<head>
<script type="text/javascript">
function hideImages() {
for(var i=0; i<document.images.length; i++) {
document.images[i].style.visibility = 'hidden';
}
}
function showImages() {
for(var i=0; i<document.images.length; i++) {
document.images[i].style.visibility = 'visible';
}
}
function eraseImages() {
for(var i=0; i<document.images.length; i++) {
document.images[i].style.display = 'none';
}
}
function displayImages() {
for(var i=0; i<document.images.length; i++) {
document.images[i].style.display = 'inline';
}
}
</script>
</head>
<body>
<img src="browsers.gif" id="b" width="150" height="150" />
<img src="amazon_cart.gif" width="150" height="150" />
<img src="screenshot-konqueror.png" width="150" height="150" />
<p><input type="button" onclick="hideImages();" value="Hide Images" />
<input type="button" onclick="showImages();" value="Show Images" /></p>
<p><input type="button" onclick="eraseImages();" value="Erase Images" />
<input type="button" onclick="displayImages();" value="Display Images" /></p>
</body
</html>
Excuse my ambiguous wording, but notice the difference between "Display" and "Hide" |
|
#6
|
|||
|
|||
|
MadCowDzz, I'm really going to make use of that code in the future! It's not my post, but thanks!!
|
|
#7
|
||||
|
||||
|
Awesome, thanks!
Notice though, display:none and visibility:hidden do two seperate things. The first collapses the entire image, while the latter simply makes it invisible [keeping a placeholder for the image] In relation to the original question, I think defining a print layout in CSS is the best solution... its a current solution that makes way for future technologies... Javasacript however is often disabled by users and is very buggy on older version browsers. I still think my Javascript code is pretty neat though =) Gotta love the DOM |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > How can I print whole window without images |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|