简体   繁体   English

如何加载外部JS文件并调用 <script></script> 在Moodle页面上?

[英]How to load external JS file and call in <script></script> on page for Moodle?

I arelady found how to load external JS file into moodle? 我是女士发现如何将外部JS文件加载到moodle中? but it doesn't solve my problem. 但这不能解决我的问题。

I got an external JS file must be loaded as it's the VOD service's player. 我收到一个外部JS文件,因为它是VOD服务的播放器,因此必须加载。

Having to call it in <script></script> in my course's video page like so, 像这样,必须在课程视频页面的<script></script>中调用它,

 <script type="text/javascript">
 (function(){ 
   var option ={"auto_play":"0","file_id":"someid","app_id":"some_app_id","width":0,"height":0,"https":1}; 
   new qcVideo.Player( "id_video_container_someid" /* this is the div id */, option ); 
 })() 
 </script>

So this qcVideo is Uncaught ReferenceError: qcVideo is not defined as Moodle uses require.js to load js files, and I'm not familiar with that. 因此,此qcVideoUncaught ReferenceError: qcVideo is not defined因为Moodle使用require.js加载js文件,对此我并不熟悉。

The js file is h5connect.js . js文件是h5connect.js

I tried to put it in my theme's javascript folder and amd/src folder. 我试图将其放在主题的javascript文件夹和amd/src文件夹中。 and in theme's config.php like this $THEME->javascript_footer=array('h5connect'); 并在主题的config.php中,像这样$THEME->javascript_footer=array('h5connect'); both not working. 两者都不起作用。

So what exactly I should do to make this qcVideo.Player work? 那么,究竟该怎么做才能使qcVideo.Player正常工作?

You need to first include the JS file and then you can put the tag. 您需要先包含JS文件,然后才能放置标签。 Then it should work. 然后它应该工作。

$PAGE->requires->js('/local/programmanagement/module.js'); Put your script tag after it. 将您的脚本标签放在后面。 It seems u are putting script tag before the js lib loaded. 看来您正在将脚本标记放在js库加载之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM