Am Mittwoch, 24. März 2010 16:14:25 UTC+1 schrieb ppgl:
>
>
> Is this achievable? I want to write a greasemonkey script that alters
> the page (eg. adds a logo at the top, or any similar simple
> modification) only when the user prints the page (either by hitting
> the File > Print Preview or File > Print menus in Firefox).
>
>
>
8 years later I  have been confronted with this topic the other way round.

The following holds for GreaseMonkey 3.11 used with FF 45.0.9esr:

Yes and No. It is affirmatively achievable, but you cannot exclude the GM 
script from running with the "screen" page.

What you can do is to check with *window.mediaMatch("print").matches*, 
whether the Print (Preview) is issued. Thus, wrap your script into the 
following if statement:

if (window.mediaMatch("print").matches) {
>
//
>
/* script goes there */

//
>
} 
>
 
As I already said, the GM script is run in the normal page.
However, it is *rerun* in the print preview, but under severely changed 
conditions.
The window.location.href changes to *about:blank* and *unsafeWindow* has 
become unusable for importing any value, as the page window in the print 
preview has no access to the page window of the "screen" page, while the 
author/page scripts are *not rerun* effectively.
In the meanwhile, I would like to have a metadata option like @noframes, 
call it @noprint, that prevents the user script from running in the print 
preview, but my own advice applies to myself though. Otherwise I would get 
tedious error lines in the Browser Console when relying on imports from 
*unsafeWindow*.

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to