Hide IE's header and footer when printing

Discussion in 'ASP .Net' started by Peter, Jun 11, 2009.

  1. Peter

    Peter Guest

    Hi

    I have a button control in my code to print the page but every time it prints out the IE's header and footer's settings like doing
    the File/Print option.

    <input type="button" onClick="window.print()" class="hide" value="Print"/>

    Any easy way to not printing the header/footer for that button ?

    Thanks
    Peter
    Peter, Jun 11, 2009
    #1
    1. Advertising

  2. "Peter" <> wrote in
    news::

    > Hi
    >
    > I have a button control in my code to print the page but every time it
    > prints out the IE's header and footer's settings like doing the
    > File/Print option.
    >
    > <input type="button" onClick="window.print()" class="hide"
    > value="Print"/>
    >
    > Any easy way to not printing the header/footer for that button ?
    >
    > Thanks
    > Peter
    >
    >
    >


    Do you mean the page information?

    Regardless, you can set up a print CSS stylesheet to get rid of things, or
    include them.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    ******************************************
    | Think outside the box! |
    ******************************************
    Gregory A. Beamer, Jun 12, 2009
    #2
    1. Advertising

  3. On Jun 11, 6:12 pm, "Peter" <> wrote:
    > Hi
    >
    > I have a button control in my code to print the page but every time it prints out the IE's header and footer's settings like doing
    > the File/Print option.
    >
    > <input type="button" onClick="window.print()" class="hide" value="Print"/>
    >
    > Any easy way to not printing the header/footer for that button ?
    >
    > Thanks
    > Peter


    Peter,

    if header/footer is a part on the page, you can try to hide it using
    media type of CSS
    http://www.w3.org/TR/CSS2/media.html

    The following example will show header and button on the screen but on
    printer only the body will be printed out.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <HTML>
    <HEAD>
    <TITLE>Link to a target medium</TITLE>
    <style>
    @media print {
    .header, .hide { visibility: hidden }
    }
    </style>
    </HEAD>
    <BODY>
    <DIV class="header">The header</DIV>
    <P>The body...</P>
    <input type="button" onClick="window.print()" class="hide"
    value="Print"/>
    </BODY>
    </HTML>
    Alexey Smirnov, Jun 12, 2009
    #3
  4. Peter

    Peter Guest

    What I mean is the "header" and "footer" in the IE Page Setup. Can you show me the way to remove them ?

    Thanks
    Peter

    "Gregory A. Beamer" <> wrote in message news:Xns9C27E763EBC09gbworldcomcastnet@207.46.248.16...
    > "Peter" <> wrote in
    > news::
    >
    >> Hi
    >>
    >> I have a button control in my code to print the page but every time it
    >> prints out the IE's header and footer's settings like doing the
    >> File/Print option.
    >>
    >> <input type="button" onClick="window.print()" class="hide"
    >> value="Print"/>
    >>
    >> Any easy way to not printing the header/footer for that button ?
    >>
    >> Thanks
    >> Peter
    >>
    >>
    >>

    >
    > Do you mean the page information?
    >
    > Regardless, you can set up a print CSS stylesheet to get rid of things, or
    > include them.
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > ******************************************
    > | Think outside the box! |
    > ******************************************
    Peter, Jun 12, 2009
    #4
  5. Peter

    Peter Guest

    Thanks Alexey but seem doesn't work. Any other ways I can try to remove those IE's headers and footers ?

    Thanks
    Peter

    "Alexey Smirnov" <> wrote in message
    news:...
    On Jun 11, 6:12 pm, "Peter" <> wrote:
    > Hi
    >
    > I have a button control in my code to print the page but every time it prints out the IE's header and footer's settings like doing
    > the File/Print option.
    >
    > <input type="button" onClick="window.print()" class="hide" value="Print"/>
    >
    > Any easy way to not printing the header/footer for that button ?
    >
    > Thanks
    > Peter


    Peter,

    if header/footer is a part on the page, you can try to hide it using
    media type of CSS
    http://www.w3.org/TR/CSS2/media.html

    The following example will show header and button on the screen but on
    printer only the body will be printed out.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <HTML>
    <HEAD>
    <TITLE>Link to a target medium</TITLE>
    <style>
    @media print {
    .header, .hide { visibility: hidden }
    }
    </style>
    </HEAD>
    <BODY>
    <DIV class="header">The header</DIV>
    <P>The body...</P>
    <input type="button" onClick="window.print()" class="hide"
    value="Print"/>
    </BODY>
    </HTML>
    Peter, Jun 12, 2009
    #5
  6. On Jun 12, 2:23 pm, "Peter" <> wrote:
    > What I mean is the "header" and "footer" in the IE Page Setup.   Can you show me the way to remove them ?
    >
    > Thanks
    > Peter
    >
    > "Gregory A. Beamer" <> wrote in messagenews:Xns9C27E763EBC09gbworldcomcastnet@207.46.248.16...
    >
    > > "Peter" <> wrote in
    > >news::

    >
    > >> Hi

    >
    > >> I have a button control in my code to print the page but every time it
    > >> prints out the IE's header and footer's settings like doing the
    > >> File/Print option.

    >
    > >> <input type="button" onClick="window.print()" class="hide"
    > >> value="Print"/>

    >
    > >> Any easy way to not printing the header/footer for that button ?

    >
    > >> Thanks
    > >> Peter

    >
    > > Do you mean the page information?

    >
    > > Regardless, you can set up a print CSS stylesheet to get rid of things, or
    > > include them.

    >
    > > --
    > > Gregory A. Beamer
    > > MVP; MCP: +I, SE, SD, DBA

    >
    > > Twitter: @gbworld
    > > Blog:http://gregorybeamer.spaces.live.com

    >
    > > ******************************************
    > > |     Think outside the box!             |
    > > ******************************************


    Well. this is client setup and cannot be controlled on server. Forget
    it
    Alexey Smirnov, Jun 12, 2009
    #6
  7. On Jun 12, 2:30 pm, "Peter" <> wrote:
    > Thanks Alexey but seem doesn't work.   Any other ways I can try to remove those IE's headers and footers ?
    >


    My example was about html parts and not about browser settings. Now I
    see what you mean. You can't change printer preferences from the
    website.
    Alexey Smirnov, Jun 12, 2009
    #7
  8. Peter

    Peter Guest

    But I have actually visted some private pages written with ASP.net actually did the job removing the header and footer when printing
    using a internally built button control inside the page but I don't know how this can be done. I have tried using the registry
    method but don't know why the Key always returned NULL and displayed "ABC" with the code below. Any suggestions ?

    -----
    RegistryKey pageKey;

    String keyValue = "Software\\Microsoft\\Internet Explorer\\PageSetup";
    String curFooter;
    pageKey = Registry.CurrentUser.OpenSubKey(@keyValue, false);
    if (pageKey != null)
    {
    if (pageKey.GetValue(@"footer",0) != null)
    {
    curFooter = (String)pageKey.GetValue(@"footer");
    Response.Write ("--" + curFooter + "--<BR>");
    }
    else
    {
    Response.Write ("DEF<BR>");
    }

    }
    else
    {
    Response.Write ("ABC<BR>");
    }

    ----
    "Alexey Smirnov" <> wrote in message
    news:...
    On Jun 12, 2:30 pm, "Peter" <> wrote:
    > Thanks Alexey but seem doesn't work. Any other ways I can try to remove those IE's headers and footers ?
    >


    My example was about html parts and not about browser settings. Now I
    see what you mean. You can't change printer preferences from the
    website.
    Peter, Jun 12, 2009
    #8
  9. "Peter" <> wrote in
    news::

    > What I mean is the "header" and "footer" in the IE Page Setup. Can
    > you show me the way to remove them ?



    Sans popping the page up in another browser window with something like
    window.open() in JavaScript, you cannot selectively show/hide browser
    elements.


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Jun 15, 2009
    #9
  10. Peter

    Peter Guest

    Thanks for your clarifications.

    Peter

    "Patrice" <http://www.chez.com/scribe/> wrote in message
    news:...
    > This code runs server side so you change the registry server side which
    > won't help...
    >
    > It could be possible to alter this but the user will have likely to give
    > its consent to install something client side (not sure what is the button
    > you are talinkg about). If it bypasses the usual IE dialog this is
    > definitely something installed client side (which requires user consent).
    >
    > Perhaps something like ScriptX
    > (http://www.meadroid.com/scriptx/about.asp). itn could be perhaps also by
    > hsioitng a webcontrol isnide the HTML page but then if you have
    > sophisticated needs it could be better to produce a real report rather
    > than printing a web page...
    >
    > --
    > Patrice
    >
    >
    >
    > "Peter" <> a écrit dans le message de groupe de discussion
    > : ...
    >> But I have actually visted some private pages written with ASP.net
    >> actually did the job removing the header and footer when printing using a
    >> internally built button control inside the page but I don't know how this
    >> can be done. I have tried using the registry method but don't know why
    >> the Key always returned NULL and displayed "ABC" with the code below. Any
    >> suggestions ?
    >>
    >> -----
    >> RegistryKey pageKey;
    >>
    >> String keyValue = "Software\\Microsoft\\Internet Explorer\\PageSetup";
    >> String curFooter;
    >> pageKey = Registry.CurrentUser.OpenSubKey(@keyValue, false);
    >> if (pageKey != null)
    >> {
    >> if (pageKey.GetValue(@"footer",0) != null)
    >> {
    >> curFooter = (String)pageKey.GetValue(@"footer");
    >> Response.Write ("--" + curFooter + "--<BR>");
    >> }
    >> else
    >> {
    >> Response.Write ("DEF<BR>");
    >> }
    >>
    >> }
    >> else
    >> {
    >> Response.Write ("ABC<BR>");
    >> }
    >>
    >> ----
    >> "Alexey Smirnov" <> wrote in message
    >> news:...
    >> On Jun 12, 2:30 pm, "Peter" <> wrote:
    >>> Thanks Alexey but seem doesn't work. Any other ways I can try to remove
    >>> those IE's headers and footers ?
    >>>

    >>
    >> My example was about html parts and not about browser settings. Now I
    >> see what you mean. You can't change printer preferences from the
    >> website.
    >>

    >
    Peter, Jun 16, 2009
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. will
    Replies:
    3
    Views:
    804
    Mathieu CARTOIXA
    Aug 6, 2003
  2. Replies:
    1
    Views:
    497
    Leif K-Brooks
    Oct 25, 2006
  3. Henrik
    Replies:
    1
    Views:
    408
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
  4. fjanon
    Replies:
    5
    Views:
    356
  5. Andrew Poulos

    Control header/footer printing

    Andrew Poulos, Mar 6, 2008, in forum: Javascript
    Replies:
    4
    Views:
    258
    Jeff North
    Mar 9, 2008
Loading...

Share This Page