0

When I load this page the script is not loading for some reason. What am I doing wrong here?

<html>
    <head>
        <title>hi</title>
        <script language="JScript.Compact">
            var script = document.createElement('script');
            script.onload = function() {
                alert("Script loaded and ready");
            };
            script.src = "http://192.168.1.106/js/min.js";
            document.getElementsByTagName('head')[0].appendChild(script);
        </script>
    </head>
</html>
SparkFountain
  • 2,110
  • 15
  • 35
  • 1
    Does this answer your question? [Trying to fire the onload event on script tag](https://stackoverflow.com/questions/16230886/trying-to-fire-the-onload-event-on-script-tag) – Jaydeep Jan 30 '20 at 13:06
  • There is mistake in thinking of html. The head-tag is not constructed to using it as an headline. This is a structure tag for html pages. So `hi`should be changed into `hi`. – Reporter Jan 30 '20 at 13:09
  • Still editing the head tag with what you told did't load the script. @Quentin This would be used in old browsers. – user1111111111111 Jan 30 '20 at 13:15
  • @user1111111111111 I've never said it will solve your issue, I just wanted to point you to an error. – Reporter Jan 30 '20 at 13:19

2 Answers2

1

I think it is working but the alert doesn't get triggered because the script you refer to isn't loaded. Try it like this:

<!DOCTYPE html>
<html>
<head>
    <link media="screen" href="style.css">
</head>
<body>
    <p>…</p>
    <img src="file.jpg" alt="" />

    <script src="responsive-nav.min.js">

    <script>
        window.onload = function () {
            console.log('Document loaded.');
            function init();
            function dosomething();
        }
    </script>
</body>
</html>
LostMyGlasses
  • 3,074
  • 20
  • 28
  • The function definitions in your script should have curly brackets (even if the implementation is missing here) to no get confused between function definition and function call. – SparkFountain Jan 30 '20 at 13:42
0
<script language="JScript.Compact">

The language attribute is obsolete, but browsers still support it.

Since you set it to an unrecognised language, browsers don't know how to execute it, so they ignore it.

Remove the language attribute.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335