The problem is that window.opener does not work in this case. The reason is because it is null. It is null because the child window will go through a few urls before the javascript can run. So without the original child's DOM (ie: access to window.opener), how can I refresh the parent page?
Don't think that would be possible with JavaScript only. The only solution I can think of is using Ajax to poll to an server-side page that indicates if the page has to be refreshed.
You can (kinda):
Hold a ref to the child in the parent.
wait for a while so the child is on the final URL
use the window ref from (1) to call a
function like registerParent(parentWindow) that takes the window
ref.
Store that somewhere and use as window.opener.
This isn't reliable, but it might work well enough. Good luck.
Maybe you should consider different approach, e.g. instead of regular calls you could do ajax in child window. That would preserve reference to parent window. Or maybe you should drop separate window concept altogether and display everything in one window using ext or jquery ui UI elements. Ext example: http://www.danvega.org/examples/extwindow/basicwindow.cfm, jQuery UI example: http://jqueryui.com/demos/dialog/
Related
I am opening HTML webresource using Xrm.Navigation.openWebResource but on closing of HTML window I want to pass values from HTML to javascript file from where it is opened. Is there call back function can be implemented?
If I open HTML window using window.open I can call parent javascript function using window.opener.functionname on close but click but I want to know how I can pass values to parent javascript file on close button click of HTML window.
I tried with window.parent.opener.Functionname() but it is not working - getting functionname is undefined but it is defined in parent javascript. Pls suggest.
If you're using the 'old' (as it not the unified interface) user interface with turboforms enabled then the parents javascript is actually in a extra iframe called customScriptFrame, and not on the parent itself.
To call something on the parent you can use
parent.customScriptsFrame.functionname() for IE
and
parent.customScriptsFrame.contentWindow.functionname() on chrome.
On the unified interface its much the same, but far more troublesome.
Now the scripts are in a iframe called ClientApiFrame_[n] where [n] is some random number. And i haven't found a good way to determin that number ahead of time from a webresource.
You could go over all frames of the parent in javascript (parent.frames) to find one that has a id that starts with ClientApiFrame_ but that will throw errors trying to read frames with sources set to external domains, and i dont think is very good practice.
Another possibility is registering the function you want to call with the parent ahead of time. so in the main javascript use this.
parent.functionname = functionname
And then from the webResource you can use the normal
parent.functionname
If the webresource is embedded in the form, then use window.parent
If you Xrm.Navigation.openWebResource to open it, then use window.opener
I'm playing around with a few ideas for a project, and one of them needs to somehow have communication between 2 different browser pages/windows/tabs. My goal is this:
I have a main page that has a link that opens a new tab/window. In that window, there is the choice to 'navigate' a part of the main page. The issue is, to my knowledge, there are no physical ties between open windows (and no handle on the 'parent' window accessible by the child).
I've been trying to use opener to reference the parent window, but functions and elements are not responding to my calls from the child.
Is there any way for a child/other window to access elements/functions on a parent window?
I'm attempting to avoid using simulated tabs/frames (which would be easy enough to just reference the parent, or window element to accomplish the goal).
Yes, actually that is possible. If you use window.open() in JavaScript, you can use window.opener. and submit whatever requests you would normally make. Like:
window.opener.document.getElementById('id').innerHTML = "hello";
or using jQuery,
$(window.opener.document).find('#tableInParent').html("hello");
Read more here: http://wisercoder.com/javascript-jquery-parent-windows/
JSFIDDLE HERE
I hope this helps!
I am trying to develop an interactive widget that utilizes jQuery within an iframe, but relies on the jQuery object that already exists in the parent document rather than making an additional server request for its own jQuery instance. This is significant because the widget will be loaded into the parent document several times on a page - therefore requiring an http request each time it appears on the page is not desired. Instead, I would like to pass the parent's jQuery object instance (I am certain it will be available in the parent document) to be used within the iframe.
With the understanding that this is a "friendly" iframe (i.e. it is permitted to openly communicate with the parent document), I assumed it would be as simple as:
window.jQuery = window.parent.jQuery;
While this seems to provide the jQuery namespace to become available within the iframe (and logging this namespace shows the expected jQuery function string), it does not seem to be able to reference elements within the iframe. For example:
window.jQuery = window.parent.jQuery;
console.log(jQuery); // logs: function (e,t){return new w.fn.init(e,t,r)}
console.log(jQuery('#elem-in-iframe')); // logs: []
Therefore it seems like the jQuery object being passed into the iframe from the parent document is still limited by the scope of the parent.
Ultimately, I have had to settle for creating an independent instance of jQuery within each iframe that loads on the page - so instead of loading the jQuery library once on initial page load, it is loaded on initial page load as well as each time the widget is injected into the parent document. While this does not inhibit the parent window from loading, as the iframe loads independently, it is not the desired result. I would like to explore how it may be possible to inherit and use jQuery from the parent within the iframe.
I think you are wrong in your assumption
therefore requiring an http request each time it appears on the page is not desired
jQuery will be cached by the browser as long as it is getting it from the same URL. It is basically a free request.
Now, the reason you can't "share" the jQuery object as you want, is that selector's have a context.
A DOM Element, Document, or jQuery to use as context
The default is document (I believe), and as you are accessing the parents object, it's default is the already set document. You should be able to do:
window.jQuery = window.parent.jQuery;
jQuery('#elem-in-iframe', document)
In the iframe to pass in the iframes window as the context, and then it should theoretically work.
You may even be able to do this in the iframe:
window.jQuery = window.parent.jQuery;
$ = jQuery(document);
and then you can just do
$('#elem-in-iframe')
The Filepicker.io modal widget (specifically the "IMAGE_SEARCH" service) appends to the window.history in the DOM after a search is made. This creates an issue working with Backbone.js when attempting to go back a previous page.
What causes this, and is there any way to prevent it?
[edit] Incorrectly referenced "IMAGE_SEARCH"
What causes this:
Navigation around the modal manipulates window.location.hash for compatibility with the window view and a number of other conveniences. Why these changes are affecting the window.history outside the iframe sandbox, I'm not sure.
How to prevent it:
I'm looking into whether we are leaking state somehow, but one easy way to prevent it is to use the {container: 'window'} option for filepicker.pick(), so that the dialog is created in a separate window.
i believe that i have to use an array but im not sure where it should be placed and how it should look. im working with javascript and am kinda new at it. should the array be in the tags? or the tag? or should it be inside of the tags but outside of the other two? im lost. should the array be written in just the parent file or the child file? or both? i have created two different pages and now i want the button on one page to return the other page and the button on the child page to close the window. which i think involves the close() option since i used the open() to bring up a new window.
It is unclear what you mean. The way one window accesses another window's properties depends on how they relate; from "child" frame to parent, from parent to "child", from "child" to "sibling"...
If you want to access another frame from within a frame, you're probably best off giving the other frame an id and using something like parent.getElementById("yourId").contentWindow. This will give you the other frame's window object, on which you can call close().
I think this link explains how to access windows, frames and parents.