Hongmu Notes
Home Summary of pitfalls Uncaught TypeError: document.currentScript is null
Summary of pitfalls

Uncaught TypeError: document.currentScript is null

Uncaught TypeError: document.currentScript is null

if document.currentScript Return null, which usually means that the JavaScript file is not passed <script> Tags are imported directly, but loaded through other methods, such as using a module loader (such as RequireJS) or dynamically created through JavaScript <script> element.

In this case, you can try the following workarounds:

  1. Pass variables directly: If you use another way to load the JavaScript file, you can pass variables to functions or objects in the JavaScript file directly from where the file is loaded. For example, if you use a module loader, you can pass variables as arguments to functions in the module.

  2. Wait for the DOMContentLoaded event to fire before executing JavaScript code: DOMContentLoaded After the event is triggered, it is guaranteed that the entire document has been parsed, including the loading of the JavaScript file. you can DOMContentLoaded Execute JavaScript code within the event handler rather than relying on document.currentScript

for instance:

document.addEventListener('DOMContentLoaded', function() {
    var player = videojs('my-video');
    
    // 获取 videoMd5 值的方式可能需要调整,具体根据你的情况来决定
    var videoMd5 = '<?= $videoMd5 ?>';
    
    var progress = localStorage.getItem('video_progress_' + videoMd5);
    if (progress) {
        player.currentTime(progress);
    }
    
    player.on('timeupdate', function() {
        localStorage.setItem('video_progress_' + videoMd5, player.currentTime());
    });
});

Make sure to DOMContentLoaded Executing JavaScript code within an event listener can resolve the issue in some cases document.currentScript Return null problem.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Browser caching increases the speed of secondary visits to your website

Browser caching increases the speed of secondary visits to your website Summary of pitfalls

Use browser caching of official words: If users will visit your website multiple times, browser caching of static resources can save users time. Cache headers should be applied to all cacheable static resources, not just to a small subset of static resources (for example, images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDF files, etc.). Normally, HTML doesn’t…
👁 202

Recommended reading

Environmental Water Management Website Template 0042

Environmental Water Management Website Template 0042 Practical Collection Yiyou template

This set of eyoucms templates is suitable for the environmental water treatment industry. The design style is professional and environmentally friendly, and can display water treatment projects, water treatment projects and technical solutions. It helps environmental water companies demonstrate their strength online and attract government and corporate customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Summary of common problems in the installation of Yiyou CMS Yiyou CMS (Ey...
👁 55
(Adaptive mobile version) HTML5 – Simplified/Traditional Chinese fonts; Green wide-screen logistics and transportation website using PBootCMS template; Responsive, professional express delivery and freight transport website source code download – 0615

(Adaptive mobile version) HTML5 – Simplified/Traditional Chinese fonts; Green wide-screen logistics and transportation website using PBootCMS template; Responsive, professional express delivery and freight transport website source code download – 0615 Practical Collection pbootcms Template

An HTML5 PbootCMS responsive website template designed for green logistics and transportation businesses, compatible with both PC and WAP devices. Its fresh and professional design makes it ideal for express delivery and freight companies to showcase their service networks, aiding in brand promotion across both mainland China and Taiwan markets. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 44
Grain and Rice Drying Equipment Website Template 0667

Grain and Rice Drying Equipment Website Template 0667 Practical Collection Yiyou template

This EyouCMS template is ideal for the grain and rice drying equipment industry. Its professional agricultural design style is perfect for showcasing drying equipment products, grain processing solutions, technical specifications, and agricultural applications. It helps agricultural machinery companies showcase their products online and attract agricultural cooperatives and farm owners. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Questions About EyouCMS Installation...
👁 32
(PC + WAP) pbootCMS – Green Energy & Energy Conservation & Environmental Protection Enterprise Website Template; Download Atmospheric Wide-Screen Scrollable Website Source Code – 0010

(PC + WAP) pbootCMS – Green Energy & Energy Conservation & Environmental Protection Enterprise Website Template; Download Atmospheric Wide-Screen Scrollable Website Source Code – 0010 Practical Collection pbootcms Template

A PbootCMS corporate website template featuring a wide-screen scrolling design, specifically tailored for the green energy and energy-saving & environmental protection industries, and compatible with both PC and WAP devices. This template boasts a modern design style with strong visual impact, making it ideal for businesses showcasing environmental technologies or new energy products. The full-screen scrolling effect vividly presents the brand story and product advantages, enhancing the user browsing experience. Template Display | Installation Instructions | Website Backend: /admin.php | Username: a...
👁 56
Heavy Industry Steel Machinery Website Template 0043

Heavy Industry Steel Machinery Website Template 0043 Practical Collection Yiyou template

An eyoucms website template targeting the heavy industry steel machinery industry. The design style is tough and grand, and can display steel products, heavy machinery and industrial scenes. It helps heavy industry companies establish a strong brand image online and attract industrial customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Summary of common problems in Yiyou CMS installation Yiyou CMS (E…
👁 40
(Adaptive mobile version) Responsive high-end website development – PBootCMS website template; Download source code for websites designed by internet marketing agencies – 0616

(Adaptive mobile version) Responsive high-end website development – PBootCMS website template; Download source code for websites designed by internet marketing agencies – 0616 Practical Collection pbootcms Template

A responsive, high-end website development and digital marketing PbootCMS template compatible with both PC and WAP devices. Featuring a creative, tech-driven design style, this template is ideal for web development agencies to showcase their portfolio, services, and technical expertise. It helps online businesses present a professional online image and attract corporate clients. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 38