10

The following code to open a calendar in popup window, works in all browsers but got "permission denied" error in Microsoft Edge browser.

popupWindow.document.writeln("<HTML>\n<TITLE>"+ title +"</TITLE>\n<link href='calendar.css' rel='stylesheet' type='text/css'>\n<HEAD>\n" + js + "</HEAD>");

The code before this:

popupWindow = window.open("","CAL1","toolbar=no,location=no,status=no,
    menubar=no,scrollbars=auto,resizable=no,alwaysRaised=no,dependent=yes,
    titlebar=no," + strDims + ",left=" + xoffset + ",top=" + yoffset );

Anybody knows why this is happening?

joeltine
  • 1,610
  • 17
  • 23
Jing
  • 101
  • 1
  • 6
  • I'd love to see an answer to this as well. Some of our tests that do `window.open` and `doc.write` in MS Edge started failing with "Permission denied". – joeltine Nov 03 '15 at 23:51
  • Are you opening this popup automatically on page load, or does it open as the result of some user interaction (i.e. clicking a button)? It seems that, if you try to open a popup automatically with no explicit user interaction to trigger it, Edge will always block it. Even if you select "always allow", Edge will still keep blocking it. I'm unable to reproduce your "permission denied" error, but I found this bug which may be related. I can't reproduce it either: https://connect.microsoft.com/IE/feedback/details/1948354/permission-denied-error-with-accessing-addeventlistener-of-a-popup – MarkPlewis Nov 05 '15 at 20:03
  • Maybe try validating the HTML in your document.writeln call. The `title` and `link` elements should be nested inside the `head` element and maybe you should try adding a `body` element and a closing `html` tag. Also, I don't know what your `js` variable contains, but you may need to do something like this with your `script` tags: http://stackoverflow.com/questions/236073/why-split-the-script-tag-when-writing-it-with-document-write – MarkPlewis Nov 05 '15 at 20:14
  • try to do `popupWindow.document.open()` first, then use `document.writeln('your-html')` and finally `document.close()` and see if it's better – Zorgatone Nov 09 '15 at 07:31
  • you need a setTimeout or load event to allow the returned window object to have a fully populated document object. – dandavis Nov 10 '15 at 06:29

2 Answers2

8

I think the problem here is the same origin policy. IE (and most likely Edge as well) probably considers a window opened with a '' (blank) URL as being in a different domain than the calling code. Try opening a blank HTML page for example instead of an empty URL.

Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189
1

It's because of Content Security Policy.

Shortly, you have to tell Edge to work unsecure from server side. https://docs.webplatform.org/wiki/tutorials/content-security-policy

Check other links here https://msdn.microsoft.com/en-us/library/dn904195(v=vs.85).aspx

unconnected
  • 991
  • 1
  • 10
  • 21