Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old July 18th, 2008, 02:14 PM   #1
New Member
 

Join Date: Jul 2008
Location: Spain
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 multimediaenglish is on a distinguished road
Printing problems switching different print stylesheets

I have a page with 10 videos, each with a text box made with <div>. I put an image button for every text box so that users can print only the text for that video. I spent days searching the Net and experimenting before I could figure out the way to do it, so I'll put my question at the end and, first of all, here's how I did it, so that it can help other people (this way is very simple, compared to some complicated non-working solutions I found on the Net):

I made one external stylesheet document with the configuration of the page for screen, and 10 stylesheets for the printing of the 10 videoscripts:

<link rel="stylesheet" type="text/css" media="screen" href="textboxes.css">
<link rel="stylesheet" type="text/css" media="print" href="printsVideomix/print1.css" >
<link rel="stylesheet" type="text/css" media="print" href="printsVideomix/print2.css" >
etc.

In every print stylesheet I included this code to disable all the text boxes divs except the one I wanted to print. This code is in print1.css, to print the first videoscript and hide the other 9:
div.imprimir1 { display:block; padding: 5px;}
div.imprimir2 { display:none;}
div.imprimir3 { display:none;}
etc.

Then I wrote the following script code in the head of my web page:

<!-- FUNCTION TO CHANGE EXTERNAL STYLESHEETS AND PRINT-->
<script language="JavaScript">
<!--
var doAlerts=false;
function changeSheets(whichSheet){
whichSheet=whichSheet-1;
if(document.styleSheets){
var c = document.styleSheets.length;
if (doAlerts) alert('Change to Style '+(whichSheet+1));
for(var i=0;i<c;i++){
if(i!=whichSheet){
document.styleSheets[i].disabled=true;
}else{
document.styleSheets[i].disabled=false;
}
}
window.print();
}
}
//-->
</script>

and then I called that function from a image-button using this code:

<a href="javascript:changeSheets(3)" >
<img style="[....blah, blah, blah....]" onClick=" window.location.reload();">
</a>
The line: <a href="javascript:changeSheets(3)" > is calling the css shifting script to load the css to print the first videoscript. I found that to print the first print stylesheet I had to send the number 3, and number 4 opens the second stylesheet and so on. I suppose that’s because I have two other link-rel labels before my print stylesheets (so this script is probably counting the number of total link-rel in your header). If you try this script, change the numbers and see what numbers work for you.

The code: onClick=" window.location.reload();" at the end of the image-button code is reloading the page, so that it gets back the original stylesheet for screen (for some reason, when the script changes the print stylesheet, the screen changes format and it gets all messed up, so I need to restore the screen stylesheet)

You can see all the code and everything, and see how it works here:

http://www.multimedia-english.com/videos/videomix.htm

THE PROBLEM IS...
And here's the catch. If you are using Firefox, you have no problem, you click on one "Print" button and you get an impression of that videoscript. Beautiful.
But if you are using Internet Explorer (at least up to v.6, I don't know about v.7), you click on the button and you get your page reload but no printing at all.

BUT IF WE MAKE A LITTLE CHANGE...
Just let's take away the OnClick part in the image-button code:
<a href="javascript:changeSheets(3)" >
<img style="[....blah, blah, blah....]" onClick=" window.location.reload();">
</a>

And now we can take the reload function up into the code of the head script, right after the window.print(); like this:

window.print(); window.location.reload();

Now, you solved things up for Internet Explorer, which is working beautifully, but Firefox refuses to print anything.

So my question is: does anybody know how I can fix my script so that both users of Firefox and IE can print my videoscripts?!
After some days of struggle I just reached my limit. My knowledge of Javascript is close to zero, so I don't think I can get any further on my own.

Of course I've been thinking of just making a print-friendly version for every videoscript and then create a link to the page, but that option was there from the beginning and that's precisely what I don't want to do (I'm changing vids weekly, there are many other things to update on my site and I want to simplify things as much as possible).

Any help will be welcome, thanks in advance

PS- if you enter my page and everything’s working well, that means that somebody helped me out and now it'
multimediaenglish is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 19th, 2008, 01:10 PM   #2
New Member
 

Join Date: Jul 2008
Location: Spain
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 multimediaenglish is on a distinguished road
Re: Printing problems switching different print stylesheets

I've been told that this page is working fine with Internet Explorer v7, so the problem is probably just for IEv6 and earlier. I don't know about Opera and others though, all I know is that it works fine with Firefox v2.x.
multimediaenglish is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 21st, 2008, 05:16 PM   #3
New Member
 

Join Date: Jul 2008
Location: Spain
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 multimediaenglish is on a distinguished road
Re: Printing problems switching different print stylesheets

well, I finally solved it.

First, I had the instruction: onClick="window.location.reload();"
This instruction was in the button, and there was also a call for the script. If I put the reload instruction inside the script then it would work with IE v.6 but not with Firefox anymore.

So the solution was this simple:

Instead of the reload function, I used this instruction:

window.location.href ="http://www.multimedia-english.com/videos/videomix.htm";

I put the instruction inside the script, and now it works fine both with IE and Firefox.

Mission accomplished!
multimediaenglish is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old July 22nd, 2008, 04:30 PM   #4
Highly Reputable Member
SuperMember
 
D3niss3's Avatar
 

Join Date: Aug 2007
Location: Pearl of the Orient
Posts: 557
Blog Entries: 1
Thanks: 4
Thanked 20 Times in 17 Posts
Rep Altering Power: 0 D3niss3 is on a distinguished road
Re: Printing problems switching different print stylesheets

Awesome! In three days time, you able to solve it yourself!

Good to hear! Congrats to you!
__________________
"When law and morality contradict each other, the citizen has the cruel alternative
of either losing his moral sense or losing his respect for the law."
-Frederic Bastiat
Web Design & Development
D3niss3 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
error , javascript , print , stylesheets


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
loading different stylesheets on click kathyc JavaScript 1 June 30th, 2008 03:01 PM
How-to: automatically Printing from FLASH without "Print Box" Pop-up window? actiontintoy Flash and ActionScript 3 April 13th, 2008 09:59 AM
Switching from ASP to ASP.net jsa .NET 1 November 27th, 2006 02:26 PM
Alternate stylesheets problem masonbarge JavaScript 4 May 17th, 2006 03:01 PM
Alternative stylesheets benbacardi HTML, XHTML and CSS 18 May 14th, 2004 10:22 AM


Search Engine Optimization by vBSEO 3.2.0 RC8