I have a an iframe that has a report within it. What I also have, is a feature to allow the user to detach the report within the iframe and open it up in it's own window, using window.open() call.
My problem is, when I press on the detach button, the whole report that initially loaded in the iframe actually goes through the motions of re-running the query again and so presents the user with a white screen until the report eventually renders again.
Is there anyway of not re-running the report in the detached window or somehow grabbing a cached version?
Thanks.
If you already have the HTML on the client side, you can write that to the popup window without going to the server.
var w = window.open();
w.document.write("Text in new Window");
That will open a window and write some text to it. All you need to do now is get the content from your iframe and write it to the new window. Bingo :)
BTW IMO: Opening new windows in browsers should be avoided where possible as many browsers block it and most automated UI testing tools don't support it.
EDIT (in response to comment):
Here is an example of reading from and writing to an iFrame using the jQuery JavaScript library.
// Write to
$("iframe").contents().find("body").html("Test Html")
// Read from
alert($("iframe").contents().find("body").html());
This basically finds iframe elements in the document and reads and write content to them. If your not using a JavaScript library I highly recommend learning up and using one of them.
BTW: My advice on popup windows also holds for iframes. You should avoid using them where possible.
Related
Part of my extension involves accessing a webpage and then programatically performing certain functions for the user. The app would obviously be much cleaner if the user did not have to see all this happening in a browser window.
In some situations this could be achieved by, displaying other content (useful to the user) in a browser window, loading the screen with the programmatic elements in an iframe and manipulating them through an action script that triggers on the page load of the page loaded in the iframe.
However, for my purposes this is obstructed partially by the cross-domain limitations and totally by the fact that site in question does not allow iframes.
(One solution was to reverse this process--i.e. direct the browser to the correct page and throw up the useful content in front of it, thereby hiding the noise while loading the page in the browser. This works but it is horrible for obvious reasons)
Is there any clean way to either:
Open a chrome window but keep it hidden?
or
Load a page (i.e. have a DOM built etc) without doing so in a window/tab?
Have you tried using
chrome.windows.create({url:yourUrl, focused:false, state:"minimized"}, function(hiddenWindow){
//do whatever with hidden window
});
or having an <iframe> in the background.html of your extension?
I have a html file that will be run locally using IE. I want it to function more like an app, it will not be published to a site, I'm only using IE to view it. The code that follows will provide basic functions to do simple calculations. I've not been able to successfully use the window.onload event to create a new window that removes the scroll bar, title bar, menu, etc without it looping. I'm not sure if an If statement or a while statement is best for testing if the page is already open to stop the loop and I'm having a hard time understanding the syntax of how to test if the window.onload already has the window open. I guess I'm looking for some guidance on setting this up or a reference easily understood by a beginner. Thank you.
I at present have two html files. The first, its only purpose in life is to trigger the second to load as I want it to show.
function openWindow()
{
window.open("CouchShifts.html", "", "status=no,toolbar=no,menubar=no,navigationbar=no,location=no,resizable=no,scrollbars=n, width=440,height=200'");
}
window.onload = openWindow()
window.close("test.html")
I had tried to incorporate this idea into the original html file without success. Any starts on how to better handle this so that when the standalone html file is double clicked from the desk top it open as specified above only once without looping?
It's not wise to check window is open or not in the same windows onLoad. You should check it rather in the event that actually opens the window.
Here are some solutions for this.
Check if window is already open window.open
https://stackoverflow.com/a/10467344/672455
Hard to come up with a title, my apologizes.
Problem is this: Since modern web-browsers disable pop-up windows I am in need of a work-around.
When a visitor comes to the website they are prompt to press a button. Once the button is pressed a pop-up window is launched with the following code:
w = window.open('/audio/audioplayer.php?id='+audioId, 'audioplayer', params);
Now that the pop-up is open I would like when the visitor views other pages the pop-up is loaded with specific information based on whatever page they are on.
I am not sure if this is possible or how I can do this (check if the pop-up window is open, and if it is load the information, and if its not re-display the button)
I don't think it is possible to detect where the popup is open of not.
Have you thought about using a dialog? Rather than a popup?
window.open returns a windowObjectReference - this is the only way you can talk to the popup window. In particular, you can tell if that window is closed with the windowObjectReference.closed attribute. And the popup window has a window.opener attribute that references the parent window back. You can use both to communicate.
However, it seems you want to keep this communication between page loads. You have a few options:
Try to keep the link between windows as long as possible. The problem is that when the parent window reloads, all the javascript variables reset and there's no way to recover the reference to the popup - unless the popup sets it using window.opener. This link shows this approach and also another one with frames.You could consider it either ugly or clever. But it's not perfect. (You can't do anything if the user opens a page in a new link)
Communicate with the server using ajax from both main pages and the popup page. When a top level page wants to send a message to the popup, they start an XMLHttpRequest to your server which notifies a script which leaves a message in a "queue". The popup page regularly polls/long-polls the server with XHR too (or server sent events, my personal favorite) and updates its own contents accordingly.This might be a bit more complex/expensive than you'd like but it's also the safest solution.
Don't use popups, like the other answer suggested. A div with position: fixed could get you a similar result, and might save you from that method of communication between windows, however it also leads to having one dialog per page, so you need to ask the server if another instance of the dialog is running. Not quite sure if other methods of sync are viable for this (localstorage?)
I have this script on my html page:
<script language='javascript'>parent.resizeTo(550,510);</script>
I'd like to add to it so it positions the window in the middle of the screen. Also, I want to remove the address and tool bars (I've managed to hide the scrollbars by using body{overflow:hidden;}).
I know how to do this using JS upon opening a new window from the browser but this needs to work from clicking a link on a PDF.
Does anyone have any suggestions? Thank you!
You can't remove address bars, etc. from the user's browser window (even if the user is only you) unless you create a new window object. And the trend is toward removing more and more of your ability to "customize" such popup windows, for security reasons.
This is actually a feature, not a bug. Think about it.
If you're opening a browser window from a separate application, the page starts off its life with a completely-decorated browser window. There's no way to make those decorations go away after the page is loaded.
While I seriously doubt the justification of your desires the way to do it is to somehow open a window. That means that your pdf links to a page that as its action will open a window with an url that has the actual content. The pdf links to a page that is basically a redirector. You give the final URL as a parameter and launch it. Of course you need to disable the popup blocker for this to work, but you should not even consider doing this on a public (no browser control) website anyway. You also might want to add to the redirector page a button that the user can click to open the page if it was blocked by the popup blocker.
This is the situation. I'm trying to provide a service where someone embedds an iframe on their website with a form in it. At the end when an ajax request comes in again I want to pop a new window with a thank you note in it. window.open does not work and my guess is because the window object belongs to the page that embedds it and not the iframe and would then be considered cross-site scripting. Is there another way of doing this?
A thought I had was, that I can create links with target="_new" in my iframe, and clicking that would actually pop another window. Maybe I could create this link and "click"/trigger it with javascript?
I do have control over what the user embedds so potentially I could include a script there too, but the less code there, the better obviously.
Any takes?
window.open does not work and my guess is because the window object belongs to the page that embeds it
I don't think so. window as seen by your script will generally be the window object of the document inside the iframe.
More typically, a window.open on an XMLHttpRequest completion will be blocked by browsers' built-in pop-up-blockers. They usually only allow new windows to be opened in direct response to user interaction (typically, in the onclick event handler).
Maybe I could create this link and "click"/trigger it with javascript?
No, otherwise everyone would be doing that to circumvent blockers!
If you're starting an XHR and you know you're going to need a pop-up in the future you'll have to open it now and put some filler content in until the XHR returns, at which point you can update its contents.