11

I have a page that needs to access to window.safari.pushNotification. Everything works fine when you load that page. However when this page is included in a iframe window.safari is undefined.

This problem occurs even when you are on the same origin and even adding

sandbox="allow-forms allow-popups allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation"

doesn't solve the problem.

Is it an intended behavior or a bug? Is there any work around to access window.safari from inside an iframe? (I really need it)

It is simple to reproduce this issue. Just add the following code to a page and try:

  • to load it directly
  • to include it in another page using an iframe
window.addEventListener('load', function () {
  console.log('safari' in window)
});
Towkir
  • 3,889
  • 2
  • 22
  • 41
collimarco
  • 34,231
  • 36
  • 108
  • 142
  • I believe this is the intended behavior. Do you need to access that object on the iframe? You can reference the parent window's safari object through `window.parent.sfari`, will this accomplish what you need? What exactly are you trying to do? – Joshua Terrill Jan 03 '18 at 08:40
  • @JoshuaTerrill Referencing `window.parent.safari` works although same-origin policy restrictions will prevent you from accessing `window.parent` in a cross-origin iframe. – WynandB Mar 11 '19 at 06:01
  • https://stackoverflow.com/questions/20696041/window-openurl-blank-not-working-on-imac-safari – Anatsu May 21 '19 at 13:24

0 Answers0