SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Print Preview from a button

    I'm looking for a Print preview feature is like in IE File->Print Preview and i want to put it in a button. that means i want to create button, when i select on it, it will show the print preview windows like what current IE does.
    I'm currently using IE 7.
    thanks in advance.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    That option is only available from the browser menu - of course all browsers do have that menu option.

    The only option available from JavaScript is to print directly to the default printer.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    May 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    That option is only available from the browser menu - of course all browsers do have that menu option.

    The only option available from JavaScript is to print directly to the default printer.
    is it don't have any function to call and show the print preview? as i plan to create a button to show printpreview of the page.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The only print preview option in the browser is built into the File menu next to the only print option that allows you to select a printer.

    The ONLY print option available within a web page itself is the JavaScript window.print() command which prints the web page to the default printer. There is no other print options available from within the web page because the web page has no way of telling what printer(s) the system has available to it.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    May 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm really wonder how the File-Print Preview work??
    how can i call it from PHP or javascript...

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    You seem to still be a bit confused. The "print preview" is a browser feature. Javascript works within the web page that is in the window in the browser.

    You are wanting to find a way for javascript to bridge from the page to the browser. For security reasons modern browsers do not allow this.

    TBH, I don't understand why you want to do this. As felgall has said, users can do this themselves without any extra effort on your part simply by using their browser controls.

    That said, you could use javascript to change the appearance of the page to look like what you hope might possibly be somewhat similar to the actual print view (using different CSS rules?). But doing so would be iffy at best.

    So to answer your questions
    i'm really wonder how the File-Print Preview work??
    That depends on the browser, I imagine they all do it differently.
    how can i call it from PHP or javascript...
    You can't.

  7. #7
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    More than you can't... you shouldn't. The average computer user easily gets confused... if you add such functions like print into your website, people will look for it on EVERY website and then when they can't see it they'll think their browser is broken. You should ALWAYS reinforce conventions like encouraging people to use the menus provided. Why anyone would want to add unnecessary "features" into the website is beyond me, it defies every form of logic.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •