0

I'm wanting to be able to theoretically pass a URL to a window.print() (yes I know you cannot pass a url to this function) via a button. Then the print window would pop up with a page/article that you are not currently on in the browser.

For example: Let's say I am on Facebook.com and I have a share button for an article that pops up on Facebook.com. Lets say that when you click share, there is a print button that when clicked it will print the article (let's say this article is google.com for example). When I am on Facebook.com I want to be able to print Google.com using that share button WITHOUT having to even go to the website/page Google.com.

Is this something that is possible with javasript/Jquery. I have been doing a lot of research into it but not finding anything that would fit this criteria.

Thank you for your help!

I have tried setting up a jquery function that takes in a doc url and print the window but it continues to print the current page that I am on.

I have tried doing a lot of research on the idea but am continuing to see problems where people are only trying to print the page that they are currently on.

pet3r15
  • 3
  • 2
  • 1
    You can not really control it because of being in a different domain. – epascarello Nov 01 '22 at 12:17
  • If you can get the content on the page, then you can use `@media print` / `@media screen` to show/hide elements so that print looks completely different from what you see on the screen. Here's a cut-down simple version : https://jsfiddle.net/4vts9x8p/ run the fiddle then ctrl-P to get a print-preview. The problem is getting the remote content. – freedomn-m Nov 01 '22 at 13:05
  • @epascarello if it exists in the same domain, would you be able to control it? – pet3r15 Nov 01 '22 at 13:29
  • you can window.open and print it. You can use an iframe and print it. But once it is in another domain same origin policy and x frame options limit it. – epascarello Nov 01 '22 at 14:47

1 Answers1

-1

It is always possible if you work on it, with a little bit of creativity. I imagine you can fetch the content of the page through iFrame element, keep the element hidden and then print the content of it. Found that Link that might help you

Feki Hamza
  • 307
  • 1
  • 7
  • Most servers don't like iframes, eg they'll give: `Refused to display '...' in a frame because it set 'X-Frame-Options' to 'sameorigin'.` Or `Refused to frame '...' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'` – freedomn-m Nov 01 '22 at 13:00