Safari iOS not linking to JavaScript file

29 Views Asked by At

The index.html file of my website links correctly to the main.js file. I know this because:

  • I checked the filepath
  • It works perfectly on FireFox, Chrome and Safari.

However, on Safari iOS this main.js file doesn't even open.

I have noticed that embedding inline JavaScript on my page works fine across all browsers, but it seems that linking to an external JavaScript file doesn't work on Safari iOS.

A reduced example of my website:

index.html

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <!-- this works on all browsers -->
        <script>
            'use strict'
            alert('The page has used inline JavaScript')
        </script>
    
        <!-- this doesn't work on Safari iOS -->
        <script src = js/main.js></script>
    </body>
</html>

main.js

'use strict'
alert('The page has linked to a JavaScript file')

To clarify:

  • The file path to the JavaScript file is correct
  • The content of the JavaScript file does not contain any errors or unsupported features
  • My website uses HTTPS and is an ordinary static website, so there is nothing to mess things up

Why is this happening? Is there some sort of meta tag or something I can put into my HTML page to allow linking to external scripts for Safari iOS? Using inline JavaScript is not an option.

Thanks in advance. Any help would be appreciated.

(Similar question: Safari iOS not loading Javascript file?)

0

There are 0 best solutions below