0

I use the following code:

if (navigator.platform == 'iPad' || navigator.platform == 'iPad Simulator' || navigator.platform == 'iPhone' || navigator.platform == 'iPhone Simulator' && window.navigator.standalone === false) {
window.alert("We've detected you're on iOS. Did you know that you can put us on your home screen? Tap the share icon, then tap 'Add to homescreen'.");

}

To alert them there is a standalone option available, however it doesn't work... strangely I only get it when the app IS in standalone mode. What am I doing wrong?

EDIT: I actually found out that I was doing code outside of a function. I thought that this would be fine, odiously not.

ilarsona
  • 436
  • 4
  • 13
  • See here http://stackoverflow.com/questions/10639858/javascript-window-navigator-standalone-broken – elclanrs Nov 11 '13 at 00:18
  • I put that in my code... – ilarsona Nov 11 '13 at 00:20
  • 1
    Check again closely, you're comparing to `false`, but what if `navigator.standalone` doesn't exist? Also `&&` binds stronger than `||`, maybe you're missing parenthesis somewhere? – elclanrs Nov 11 '13 at 00:22
  • I'm using || to say 'or'... is that wrong? I'm fairly intermediate with Javascript but I still don't know everything. – ilarsona Nov 11 '13 at 00:23
  • Read about operator precedence, see here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence, or here http://msdn.microsoft.com/en-us/library/ie/z3ks45k7(v=vs.94).aspx – elclanrs Nov 11 '13 at 00:26
  • After reading about the operator rules, I simply split off the two statements (separated by the &&). This had no effect. – ilarsona Nov 11 '13 at 00:32
  • What is the value of navigator.platform on your device? You can use alert(navigator.platform) to get the actual value. Also, you should update the code in the question with the changes you did. Now it's impossible to see if the code is correct. – HoffZ Nov 11 '13 at 11:13

0 Answers0