lightning_missile
lightning_missile

Reputation: 2992

javascript in mobile web browsers

I have this very simple html file.

<!doctype html>
<html>
<head>
</head>
<body>
<script>alert("hi");</script>
</body>
</html>

This usually runs fine in Firefox and Google Chrome on my laptop. But when I run this in Safari in an iPhone device and Google Chrome on an Android device, the JavaScript code doesn't run. That is, no alert appears. This is extremely unusual for me. Do we need to change JavaScript code when running on mobile devices? What should I do?

Upvotes: 0

Views: 54

Answers (1)

Ravenous
Ravenous

Reputation: 485

(function(){
  window.alert('hi')
})()
<html>
  <head>
  </head>
  <body>
  </body>
  <script src="aJSfile.js"></script>
  
</html>

Add window to alert so that it says window.alert('hi') also see the core window functions supported by most browsers

https://developer.mozilla.org/en-US/docs/Web/API/Window/alert

Upvotes: 1

Related Questions