Question:
From Page A I have a link to Page B, on Page B it calls window.print() on load, which opens the print preview modal. My question is on Page A, is there an easy way to know that the print preview modal on Page B is currently open or not? (I only need this to work on Chrome)
Background:
The reason I need to get this done is that there's a problem with Google Chrome blocking parent page's Ajax calls when it has child page who has print preview modal open.
Related Questions:
Chrome browser unable to make a server call when print preview is opened
Google Chrome blocks ajax requests when print preview is opened on child window
https://code.google.com/p/chromium/issues/detail?id=139706
There's no easy way to completely solve the problem, so I only want to know whether the print preview modal is open and warn users to close the print modal on Page B before moving forward on Page A.
This looks to not be possible. Chrome doesn't just blocks ajax execution, but it also stops processing all scripts on page A.
I think your best bet is to have instructions on page B for the user to print the page. Any Javascript initiated print will pause Javascript execution on page A.
A possible solution would be to display a message on page A before opening page B in anticipation of this behavior.
Edit: pulling in information from comment below
After further thinking, the best solution would be: On page B, in the script, that calls window.print(), just before calling print, send information back to page A communicating that this is going to take place, so that page A may take the appropriate action.
Related
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.
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
I have a site where a particular page has two buttons that open pages in new tabs. One page is a preview of an item, and one is the print of that item.
// Preview button's click event
window.open('my.preview.url.com', 'preview');
// Print button's click event
window.open('my.print.url.com, 'print');
On the print page, window.print(); is call on page load.
This seems to create a bit of an issue on some browsers. Opening the print page and not closing the print preview results in all of the JavaScript being blocked on the originating page (with the buttons) and the preview page (if one had been opened previously).
This appears to not happen in all browsers. For example, Chrome displays the issue but Firefox does not.
This is similar to a similar unanswered post, which has a useful fiddle at http://jsfiddle.net/Zicane/7ntsb7hh/10/
Hoping someone might know the solution to both issues.
Problem:
Google Chrome blocks ajax requests when print preview modal is opened on child window
Details:
I have a web page - ParentPage.html with a link to child page - PrintPage.html
a href="PrintPage.html" target="_blank"
Then on my PrintPage.html I have JavaScript that invoke window.print()
$(document).ready(function() {
window.print();
}
If user goes to ParentPage.html without closing that print modal on PrintPage.html and click some button that fires Ajax calls, they are blocked until the print modal is closed.
This should be a known problem with Google Chrome, other browsers(IE, Firefox) have similar issue but they don't become problem because they simply don't allow user to navigate to other tab other than the current opened print page.
I found related questions here on SO but no solution:
Chrome browser unable to make a server call when print preview is opened
Google Chrome blocks ajax requests when print preview is opened on child window
It would be best to make the parent window's Ajax not blocked. I feel it might be possible because not all tab's Ajax calls are blocked, only this parent window. So if there's a way to make the child page - PrintPage.html not a child page of ParentPage.html, that would work.
A less ideal way would be to close the print modal on PrintPage.html when I detect user clicking on ParentPage.html. Then reopen the print modal when PrintPage.html is focused. The reopen modal part is easy, but I don't know how to close print modal from a different tab.
If above two ways won't work, I think I'll have to display a warning when the print modal is opened and user is trying to click ajax call button at ParentPage.html. Detecting if the print modal is opened from ParentPage.html might not be easy either.
Any help would be appreciated!
To reload/refresh a page from another page using JavaScript. (A page, which is already opened in the browser. I need to refresh it (not open again) from another page.)
I refer a lot, but i can't get the exact answer i want.
How to refresh another page using javascript without opening the same page in a new tab
I referred this page. But it has a parent and child page. But i need to refresh a unrelated page from another page.
Is this possible?
If so, give me some suggestion.
Explanation of my actual project:
There is a pageA from that using Ajax i called some other page(inside a div of pageA). Then by clicking a link in that div (present in page called from Ajax), it will open a pageB in new tab in the same browser. in that page, when user clicks a button, It will call another page, in that page i do a table update. After that update, pageA should be refreshed. This is the actual project what i have to do.
Assuming this is in the same browser and the same domain a simple way is as follows (pseudo code)
Page A -> controller
Page B -> page to be refreshed.
The steps are:-
Page A Calls a Javascript function (via button press for example) that writes a value of 'update: true' to local storage.
Page B has a loop of 500ms that checks this value in local storage - when it sees 'update: true' it sets it back to false and then refreshes itself.
These are all simple things to look-up how to do but if you get stuck just let me know.
Oh and same principle applies on different browsers (i.e. if Page A opened in chrome, Page B opened in Firefox) - just that instead of local storage you use a server and store the state to DB / a file.
Below is a quick example - open the two pages in different tabs then click 'refresh' in the controller apge - you will notice the 'page to be refreshed' page refreshes.
CONTROLLER
PAGE TO BE REFRESHED
first of find frames(or div) which you want to reload
for example
enter code here
var myframe=parent.frames['frameName'];
then
myframe.location.href=myframe.location.href;
i hope it will work well.
in my case it work fine.
thakns &BR
I have a Chrome extension that does word substitutions on pages. Currently I have a popup that opens when I click on a browser action which lets the user control whether or not to perform the substitutions. I also have a background script running that sends a message to content scripts when a page refresh happens using a chrome.tabs.onUpdated event handler.
My problem is that when I refresh the page no substitutions are made unless the popup is open (which is only possible when I have the inspect elements panel open on the popup, because otherwise the popup closes when I refresh).
Has anybody had experience with this behavior before? What additional instrumentation should I add to diagnose the problem? Is there a different extension architecture/code arrangement I should be using?
Thanks in advance!
If you use localStorage on a given page you can probably store whether or not to substitute words. I think refreshing a page is similar to opening a new tab, so your script gets reinjected/reloaded rather than staying open and receiving an onupdate message.