...

View Full Version : Disable script on print?



BoldUlysses
06-10-2008, 02:42 PM
Is there any way to disable a script on print? I used the negative margins CSS trick to horizontally center my page and use a script to justify it in case the browser window is too small; thing is, even with a CSS stylesheet just for printing, the script fudges things cross-browser (read: in IE).

Script:


//crossbrowser attach event functions
function AttachEvent(obj,evt,fnc,useCapture){
if (!useCapture) useCapture=false;
if (obj.addEventListener){
obj.addEventListener(evt,fnc,useCapture);
return true;
} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
else{
MyAttachEvent(obj,evt,fnc);
obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
}
}
function MyAttachEvent(obj,evt,fnc){
if (!obj.myEvents) obj.myEvents={};
if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
var evts = obj.myEvents[evt];
evts[evts.length]=fnc;
}

function MyFireEvent(obj,evt){
if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
var evts = obj.myEvents[evt];
for (var i=0,len=evts.length;i<len;i++) evts[i]();
}
// END crossbrowser attach event functions

//attach the new function:
AttachEvent(window,'load',shrink,false);
//your functions
var bdy,obj;
function shrink(){
bdy=document.body;
obj=document.getElementById('container').style;
savePage();
}
window.onresize=function() {
savePage();
}
function savePage() {
if(bdy.offsetWidth<1000) {
obj.marginLeft=0;
obj.left=0;
}
else{
obj.marginLeft='-500px';
obj.left='50%';
}
}

Markup:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>ImageWorks Display | Tobacco Fixtures &amp; Accessories | Testimonials</title>

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

<!--[if IE 6]>
<link href="css/ie6.css" rel="stylesheet" type="text/css"/>
<![endif]-->

<!--[if IE]>
<link href="css/ie.css" rel="stylesheet" type="text/css"/>
<![endif]-->

<script type="text/javascript" src="js/justify.js"></script>

</head>

<body>

<div id="container">

<!-- Logo Start -->

<?php include("logo.php"); ?>

<!-- Logo End -->

<div id="sidebar">

<!-- Search Bar Start -->

<?php include("searchbar.php"); ?>

<!-- Search Bar End -->

<!-- Common Menu Start -->

<?php include("commonmenu.php"); ?>

<!-- Common Menu End -->

<!-- Cart View Start -->

<!-- <?php include("cartview.php"); ?> -->

<!-- Cart View End -->

</div>

<div id="catalogcontainer">

<!-- Banner Start -->

<?php include("banner.php"); ?>

<!-- Banner End -->

<!-- Content Area Start -->

<h3 class="testimonialsheader">As expressed by some of our satisfied
customers,<br/>ImageWorks' dedication to absolute<br/>customer
satisfaction is not a hollow promise.</h3>

<div class="horizontalrule"></div>

<img class="testimonialicon" src="images/exxonicon.gif"
alt="exxonicon" title=""/><p class="testimonialtext">We have worked
together with ImageWorks Display and Marketing developing upscale
custom cigarette and tobacco fixtures for all of our locations. The
fixtures have met our needs for superior merchandising of the tobacco
and OTP category and are built to last so we won't need to refixture
as often as in the past. <span class="testimonialbold">The fixtures
offer the flexibility to meet the ever changing manufacturer
contracts. ImageWorks has been a great partner throughout the entire
process.</span></p><p class="testimonialnames">Mike
Askwith<br/>Global Category Director<br/>ExxonMobil</p>

<div class="horizontalrule"></div>

<img class="testimonialicon" src="images/thdicon.gif" alt="thdicon"
title=""/><p class="testimonialtext"><span
class="testimonialbold">ImageWorks Display and Marketing has played a
big part in the successful merchandising of cigarettes and tobacco in
our new convenience stores. The fixtures and signage they provide
are top notch.</span> Not only do they give an enhanced appearance to
the category, they are built to last and the versatility allows
manufacturers to achieve all merchandising contractual requirements
and marketing needs. <span class="testimonialbold">Everyone in the
industry should consider ImageWorks as their supplier of
fixtures.</span></p><p class="testimonialnames">Todd
Bostian<br/>Merchant<br/>THD FUEL Stores</p>

<p class="testimonialtext2">In developing merchandising and signage
concepts, The Home Depot Fuel was seeking to partner with experienced
companies who not only had experience with the products to be sold
but displayed a unique ability to take a look forward with
convenience store image and graphics. <span
class="testimonialbold">The interior fixtures and window signage that
was developed by ImageWorks lives up to that forward look</span> and
at the same time allows THD FUEL to be flexible with our messages and
direct with the presentation to the customer. Each fixture is
engineered in a way so that cost, ease of installation, contractual
considerations and visual dynamics are incorporated into production.
<span class="testimonialbold">We continue to work with ImageWorks as
we refine our concepts.</span></p><p class="testimonialnames">Stephen
Bottomly<br/>Director - Site Development<br/>THD FUEL Stores</p>

<div class="horizontalrule"></div>

<img class="testimonialicon" src="images/xtramarticon.gif"
alt="xtramarticon" title=""/><p class="testimonialtext">When we
needed new tobacco racks the team at <span
class="testimonialbold">ImageWorks Display took the time to work with
us to learn our needs</span>, then presented us with the solution.
<span class="testimonialbold">Thanks ImageWorks.</span></p><p
class="testimonialnames">Glenn Carroll<br/>Merchandiser<br/>Xtramart
Convenience Stores</p>

<div class="horizontalrule"></div>

<img class="testimonialicon" src="images/chevronicon.gif"
alt="chevronicon" title=""/><p class="testimonialtext"><span
class="testimonialbold">Over the past year, we have enjoyed working
closely with ImageWorks' creative and energetic team.</span>
ImageWorks is a one stop solution and offer a full range of high
quality value added services from design to implementation. They
excel in project management and have proven to go the "extra mile" to
get the job done in the most efficient way possible. <span
class="testimonialbold">It's easy to recommend ImageWorks as a
partner of choice.</span></p><p class="testimonialnames">Doug
Schweers<br/>Category Manager<br/>Chevron Canada</p>

<p class="testimonialtext2">Over recent years I have worked with
ImageWorks in a partnership to develop a large scale nationwide
refurbishment program. Their approach to this partnership has not
only supported the implementation of the project but <span
class="testimonialbold">I have found the team prepared to go above
and beyond expectations</span> to truly support the success of the
project. ImageWorks has at all times exhibited a high level of
professionalism supported by an attention to detail matched by few.
<span class="testimonialbold">I highly recommend ImageWorks as a
partner of choice.</span></p><p class="testimonialnames">Rob
McKay<br/>Global Category Manager<br/>Tobacco and
Grocery<br/>Chevron</p>

<p class="testimonialtext2"><span class="testimonialbold">ImageWorks
has been a great partner throughout our re-design and implementation
of our new tobacco back bars.</span> The store managers and field
supervision have been delighted with the unit and its ease of use.
The unit gives a upscale look while meeting our needs in terms of
merchandising and destination.</p><p class="testimonialnames">Tony
Bandiera<br/>Category Manager<br/>Tobacco - Food Service - Coffee -
Fountain<br/>Chevron</p>

<div class="horizontalrule"></div>

<img class="testimonialicon" src="images/speedystopicon.gif"
alt="speedystopicon" title=""/><p class="testimonialtext"><span
class="testimonialbold">ImageWorks Display and Marketing is our
preferred vendor for our custom made cigarette fixtures.</span> They
manufacture state of the art cigarette and tobacco fixtures. <span
class="testimonialbold">It has been a pleasure to work with
ImageWorks</span> representatives because they are eager to help us
any way they can to satisfy our needs and requirements, <span
class="testimonialbold">always keeping their promises and ensuring
our satisfaction.</span></p><p class="testimonialnames">Omar
Rachid<br/>VP, Marketing<br/>Speedy Stop Stores, Ltd.</p>

<!-- Content Area End -->

</div>

</div>

</body>
</html>

BoldUlysses
06-18-2008, 03:46 PM
Any ideas? There's got to be a conditional line to add in the js somewhere... I can't imagine it would require reworking the whole program.

rnd me
06-18-2008, 07:05 PM
you can use print only css, or show you page using screen only css.

then you don't need to disable anything.

BoldUlysses
06-18-2008, 07:39 PM
Oh I do, hence this:


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

in the HTML file.

But since the link to the javascript file is in the HTML file and not the CSS, I can't use CSS to restrict the application of the js file. Unless...

Is there a way to link to a js file like a stylesheet? Like so:


<link href="js/justify.js" type="text/javascript" media="screen"/>

??

rnd me
06-19-2008, 04:44 AM
ok, i see. you are changing style attribs which stay active even under print mode.

i can think of two solutions:
1. roll-back any modifications done by the script, resetting attribs to their original values.

2. move away from using style attribs.
put your rules like (obj.marginLeft=0; obj.left=0; , etc) into a css class.
use javascript to change the className of the tag to the class containing the new styles.
you can declare the class in a screen-only css section, and the changes wrought by javascript will fail to show up.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum