0

I open a new page and in IE(Using ie 11) window.opener is undefined. The window reference that window.open returns also is full of undefined or an empty Object.

My newly opened page needs to get the Xrm Object from the main page, since I cannot get it otherwise and need it to do all my functionality. Code:

function openCountyTab() {
  countyTabRef = window.open("countyTab", "countyTab");
  return false;
  }

And in the js file of the new tab I have var opener; window.onload = function() { ... opener = window.opener; ...}

I have tried many things, including sending it to the full url, using a Blob and creating a url from that (which returns access denied), I also need to mention that when sending window.open("fullDomainName") the Object I get back is filled with <Access Denied> tags.

Edit: I will state my problem more clearly. I need to open a new HTML page that is on the same domain and it needs to either get passed the Xrm object or get it from the window that opened it. Now, the Xrm object is needed because I use it in my script that runs on this newly opened page. Specifically, it is needed for a lib that I am using called XrmServiceToolKit.

I use this to retrieve and modify data on a server on Microsoft's CRM Platform. I have no issue with doing any of that since everything runs fine on Chrome, FF. The problem is that the XrmServiceToolKit cannot get the context ie the Xrm Object because it is null or undefined on the page. Therefore I cannot run my script as it depends on this. Therefore, I need a way to open a new page (not replace current window) in IE11 and give it this Xrm object.

Hopefully that clears it up.

Any help is greatly appreciated!

MattyP
  • 25
  • 11
  • So, you're describing a solution that doesn't work, but you hardly described what the problem is. (See: [The XY problem](http://xyproblem.info/)). Because of that, it's hard for us to help you find an alternative solution. Please elaborate on the problem, like what is this `Xrm` object, why does the window need it, and what does it contain (for instance data is more easy to serialize than an object containing code or referencing other object in the main window or document). – GolezTrol Sep 20 '18 at 17:03
  • @GolezTrol Sorry if I was unclear! I made an edit to the post and hopefully that clarifies my question better. Thanks. – MattyP Sep 20 '18 at 18:57

1 Answers1

0

The Browser Compatibility table in MDN for window.opener only lists Chrome, Firefox, and Android Webview as supporting this variable, all other browsers are unknown, and apparently not compatible.

So you should not depend on it in applications that need to be portable to all browsers.

If you need to communicate between a window and another window that it opens, take a look at the postMessage mechanism.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Do you have a suggestion on what to use for IE11? – MattyP Sep 20 '18 at 18:50
  • Maybe you can use the [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) API to communicate between the pages. – Barmar Sep 20 '18 at 19:12
  • that looks like it could work but the problem is that I cannot get the `targetWindow` which is the overall problem. Unless I am reading the docs incorrectly. – MattyP Sep 20 '18 at 19:28
  • `countyTabRef` is the target window. You run `postMessage` in the script that opens the window, not the other window. – Barmar Sep 20 '18 at 19:31
  • Oh I see because it returns the ref of that window that I opened. Makes sense, sorry did not get that part. Going to test that out and report back :D. Thanks! – MattyP Sep 20 '18 at 19:36
  • After some testing I still am unable to get it working. Seems that `postMessage` is [not working](https://stackoverflow.com/questions/21070553/postmessage-still-broken-on-ie11). It breaks when calling `window.postMessage(..args..);` with SCRIPT25 error. I can include my implementation if wanted, I am unsure where to go from here though. @Barmar – MattyP Sep 20 '18 at 21:04
  • I don't know, either. It seems like IE is making it really difficult for your windows to work together in any way. – Barmar Sep 20 '18 at 21:09