JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 14th, 2005, 05:59 AM
lina lina is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 lina User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old January 15th, 2005, 10:30 AM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
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.

Reply With Quote
  #3  
Old January 17th, 2005, 08:45 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Have you looked into using CSS to provide a Print Stylesheet?

Something as simple as img { display: none; }

Reply With Quote
  #4  
Old January 17th, 2005, 07:48 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 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:
Originally Posted by MadCowDzz
Have you looked into using CSS to provide a Print Stylesheet?

Something as simple as img { display: none; }

Reply With Quote
  #5  
Old January 18th, 2005, 10:08 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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"

Reply With Quote
  #6  
Old January 19th, 2005, 08:33 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
MadCowDzz, I'm really going to make use of that code in the future! It's not my post, but thanks!!

Reply With Quote
  #7  
Old January 20th, 2005, 08:53 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > How can I print whole window without images


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT