You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用document.createElement动态加载JS脚本失败,无请求发送至JS文件

Looks like the main culprit here is the language="JScript.Compact" attribute on your parent <script> tag.

JScript.Compact is a legacy scripting variant built for Windows Mobile/CE devices—not standard desktop or modern mobile browsers. Most browsers will ignore or refuse to execute a script tagged with this language, meaning none of your dynamic script creation code runs at all. That’s why no request is being sent to your target JS file.

Here’s how to fix this:

Step 1: Correct the parent script tag

Replace the non-standard language attribute with the standard type="text/javascript" (or omit it entirely, since HTML5 doesn’t require the type attribute for JavaScript):

<html>
<head>
    <title>hi</title>
    <script type="text/javascript">
        var script = document.createElement('script');
        script.onload = function() {
            alert("Script loaded and ready");
        };
        // Add an error handler to catch loading failures
        script.onerror = function() {
            alert("Failed to load script");
        };
        script.src = "http://192.168.1.106/js/min.js";
        document.getElementsByTagName('head')[0].appendChild(script);
    </script>
</head>
</html>

Additional checks to rule out other issues:

  • Validate the target URL: Navigate directly to http://192.168.1.106/js/min.js in your browser to confirm the file exists and is served correctly.
  • Check for CORS restrictions: If your HTML page is hosted on a different origin (e.g., localhost vs the 192.168.1.106 server), ensure the server hosting min.js sends proper CORS headers. Note: This wouldn’t prevent the request from being sent, but it would block the script from executing if headers are missing.
  • Handler order: While not causing your current issue, setting onload/onerror before assigning src avoids rare race conditions where the script loads immediately before the handler is attached.

Once you fix the parent script tag, your dynamic script creation code should run, and you’ll see the request sent to your target JS file.

内容的提问来源于stack exchange,提问作者user1111111111111

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 12:59:05