Fog Creek Software
Discussion Board




Obscure Javascript problem

The purpose of this post is two-fold
a) maybe one of you knows the answer
b) maybe you have a better resource to point me to. 

Problem (using IE):

I have a simple script containing a single line:  window.setTimeout('this.print()', 100);

As expected, this script pops up the print dialogue box with Print selected frame highlighted.  The script is on a page in a framed application, and most of the time, it prints only the relevant frame, as expected.

However, under some circumstances, the application flow requires that the user access this page from outside the normal framed application.  In other words, the user is coming from a "frameless" page [menu disappears].  All very well, except that now the print dialogue has "all frames individually" selected and "print only selected frame" is greyed out, resulting in four pages of menus to be printed as well as the desired information.  If you refresh the page after navigating to it, then it suddenly starts working.

I've tried a number of different approaches but nothing is working. Really what I want to do is specify the frame to print, but the print command appears to be more general than that. 

Suggestions?

Phibian
Wednesday, September 17, 2003

It's ugly, but....

Automatically refresh?

Steve Barbour
Wednesday, September 17, 2003

Well, "select" the frame you want to print first, like so:
  top.frames['myFrame'].focus();
  print();

Duncan Smart
Wednesday, September 17, 2003

Probably not the answer you want, but...

I really like it when websites give you a "printer-friendly view" link. 

Maybe you could pop-open the printer-friendly view and then execute the javascript?  (I don't really know Javascript).


Russell

Russell Thackston
Wednesday, September 17, 2003

I agree with Steve. Work in a refresh, then a directive to print.

JavaScript : Programming Languages :: Voodoo : Medicine

m
Wednesday, September 17, 2003

"printer-friendly views" are a waste of time and bandwidth - use stylesheets properly, e.g.:

<link rel="stylesheet" type"text/css" href="screen.css" media="screen">
<link rel="stylesheet" type"text/css" href="print.css" media="print">

You can choose to have various "furniture" you don't want printed styled with a "display:none" style.

http://www.meyerweb.com/eric/articles/webrev/200001.html

Duncan Smart
Wednesday, September 17, 2003

Yep, or use the @media rule in a single stylesheet:  http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/media_1.asp?frame=true

Wayne
Wednesday, September 17, 2003

Duncan's answer worked.  Thanks!

A "printer friendly" page doesn't work in the context of this particular application, because our users don't know what to do next after getting to the page.  If we open a new window, our users don't know enough to close it and go back.  If it's a small window, they complain that they can't see the entire invoice.  If we go to a new page with no navigation, they don't know where to go after printing, so close the browser window and start all over.

Really, for what it's worth, the print dialogue box *is* on our printer friendly version of that particular page, with the exception of the frames - which are needed for navigational purposes. Stylesheets for printing are all very well (and we do actually use them to a limited extent), but they don't automatically pop up the print dialogue for the user, and that was the behaviour that our users found least confusing and most usable.

Phibian
Thursday, September 18, 2003

*  Recent Topics

*  Fog Creek Home