Jump to content

print another page without window popup.


help_lucky

Recommended Posts

Hi all,

 

I want to print a page from another page. I have a master page with links to other page. When I click "print," it should print the another page.

The function window.print() is printing only the active page. So on click print i am opening a new window.

 

In the onload event of the target page i have used

<body onload="window.focus();window.print();window.close ();">

 

Eventhough it's working, at the same time the window is also popping up behind the printer set up screen. when i click print or cancel the window gets closed automatically.

i don't want the window to pop up. Do suggest me if there is any other alternative way..

 

Thanks for your help.

Link to comment
Share on other sites

You can't print something that doesn't exist. Therefore, if the computer has not opened/loaded the content for the page, it can't print the page.

 

However, there is one "hack" that I can think of by using some CSS properties. Using CSS you can set style properties for elements to be different based upon the "media" that the content is displayed in. For example, you can have page elements displayed differently in a browser than in a phone. One of the supported media types is the "print" media. This means you can have a page displayed ina browseer differently than it prints.

 

This is what you could do. Create a DIV on the parent page which has a display=none default setting, but a display=inline for the print media type. Then for the rest of the content in the parent page, do the exact opposite. display=inline is the normal setting so you don't need to declare that, but give them a display=none for the print media. What this means is that when viewed in a browser the "print" div will be invisible, but when the page is printed, the contents of the div is the only thing that will be printed.

 

Then it is just a matter of modifying your javascript to load the content you want to print into the DIV before initiating the print dialog for the parent page. Of course, this means the user will not be able to print the parent page as they see it. There are several posts on these forums regarding the media attributes for styles (a couple of which I have provided examples to) so you can search for those if you need more info.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.