skip to Main Content

Alright, so I have a game in React. When the user losers in this game, a new window pops up.

 const lossWindow = window.open(
    "",
    "",
    "width=500, height=300, top=200, left = 200"
  );
  lossWindow.document.write(
    '<img style = "width: 40%" src = "https://dennismarkham.github.io/week-4-game/assets/images/redx.png"><p>OH NOES, YOU ARE TEH LOOS!!!</p>'
  );

This works fine on my laptop and PC, but when I try to play the game on my iPhone with the Safari browser, the loss produces an error which says "null is not an object (evaluating ‘lossWindow.document’). Why would this be?

2

Answers


  1. You either need to bind the open function to an onclick event or use target = ‘_blank’. Maybe there is a popup blocker prevent you from open additional window as well, so you should check that.

    Login or Signup to reply.
  2. The reason you’re encountering the error "null is not an object (evaluating ‘lossWindow.document’)" on your iPhone with Safari is because the window.open() method might not be fully supported in all mobile browsers, including Safari. Some mobile browsers have limitations on opening new windows or tabs programmatically due to security and user experience concerns.

    Instead of opening a new window, you can consider rendering a modal or an overlay within your existing React application to display the loss message. Modals are commonly used to display pop-up messages or notifications in a more user-friendly and mobile-compatible way.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search