We have recently encountered an issue in our code with iPads after upgrading to iOS 9. For various reasons we open an empty window and start writing into the document once it becomes available. This usually works fine and we have various tests in place for different browser behaviour etc., but the new problem in iOS seems problematic.
When you open a new window with window.open the returned reference immediately has a document and using document write works without error. You can check the content etc. everything has worked. Then iOS decides to replace the document with a new one. Since we managed to successfully write in the first place we don't try to write again so users would see an empty page. Writing into the new document works as expected and is actually being shown to the user. Just randomly checking if the document has changed or detecting the user agent seems like a hacky solution so the question is:
Is there a better way to handle this (any events being fired) any difference on the documents/window reference to check against. Or does anyone know why iOS9 is doing this?
Here is a codepen with the working/not working code for iOS 9 http://codepen.io/anon/pen/epapGL
function openWindow(twice) {
win = window.open('about:blank', '_blank', 'width=500,height=700');
if (win.document) {
originalDocument = win.document;
win.document.write('<div>This should appear in the opened window.</div>');
noticeDiv.innerHTML = 'First write successful';
}
if (twice) {
setTimeout(writeAgain, 0);
}
}
function writeAgain() {
if (win.document !== originalDocument) {
win.document.write('<div>This is the second try. The document was replaced.</div>');
noticeDiv.innerHTML = 'Second write successful';
}
}
Edit: This is not about adding content in general, it is about the iOS 9 specific behaviour.
Edit 2: I have now opened a bug report with Apple for this. I'll see what they say.