Back

Technologies:

javascriptjavascript
htmlhtml
avatar
Tolerim
25 days ago

External scripts do not function properly in the Android HTTP server.

Here is my rephrased paragraph: I am attempting to create a console joke in HTML and have my primary script located in /system/shell.js. However, when I include this script in my HTML using <script src="system/shell.js"></script>, it does not seem to be functioning correctly on Simple HTTP server on Android 11. However, images are working correctly. Here is the code for /sh.html:
<!--/sh.html-->
<!DOCTYPE html>
<html>
    <head>
        <style>
            body {
                background-color: black;
            }
            p {
                font-family: Monospace;
                color: white;
            }
            button {
                background-color: black;
                border: 5px solid white;
                color: white;
                font-family: Monospace;
            }
        </style>
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
    </head>
    <body>
        <div id="main">
            <form>
                <table>
                    <tr>
                        <td><p>></p></td>
                        <td><input id="console-input" type="text" style="border:none;background-color:black;color:white;font-family:Monospace;"></td>
                        <td><button type="button" onclick="CmdExecute()" id="runBtn">Run</button></td>
                    </tr>
                </table>
            </form>
        </div>
        <script src="shell.js"></script>
    </body>
</html>
And here is the code for /system/shell.js:
///system/shell.js

//import { getComArg } from "../lib/console/getArg.js"

const shSystem = {
    "console": {
        "print" : function(text) {
            addElement("p", text);
        }
    }
}

function addElement(tag, text) {
    var element = document.createElement(tag);
    element.textContent = text;
    document.body.appendChild(element);
    console.log("Created element " + tag + " with text " + text);
}

shSystem.console.print("TheShell v.0.0.2")
I have found that placing my scripts within <script>//script</script> tags allows them to work properly, but I would like for them to work normally with external scripts. It's worth noting that I performed this test on a Samsung Galaxy A10s (A107F), Chrome 108.0.5359.79, and One UI Core 3.1.
Answers(2)
avatar
Vogi
24 days ago
Verified Answer
I see. It seems that you are trying to create a console joke in HTML and have your primary script located in /system/shell.js. However, when you include this script in your HTML using <script src="system/shell.js"></script>, it does not seem to be functioning correctly on Simple HTTP server on Android 11. You mentioned that you have found that placing your scripts within <script>//script</script> tags allows them to work properly. This is because the src attribute of the <script> tag is used to specify the URL of an external script file. If you want to include an external script file, you need to make sure that the path to the file is correct and that the file is accessible from the server. In your case, it seems that the path to the file is incorrect. You can try using an absolute path instead of a relative path like this: <script src="/system/shell.js"></script>. This should work as long as the file is located at the root of your server. I hope this helps! Let me know if you have any other questions.
avatar
Tolerim
25 days ago
It looks like you have a path issue with your script. When you use , the browser looks for the script in a folder called system at the same level as your HTML file. You may need to adjust the path to the script if it is not in the correct folder. One solution could be to use an absolute path that starts from the root directory of your website, like . Alternatively, if you want to use a relative path, you can use ../ to step up one directory, like if your HTML file is in a folder at the same level as the system folder. Make sure to double-check the relative path to ensure it is correct. Also, make sure that your script is not being blocked by any browser extensions or ad-blockers.
;