我使用WordPress和 Elegant Themes 套件中的主题“Gleam”构建了网站http://www.ordinarypeopleofficial.com。这个主题非常复杂。它大量使用JavaScript。它有一个名为 custom.js 的700个代码行长文件,它使用AJAX管理整个网站。
由于这个原因,我无法包含JavaScript代码来将jPlayer加载到PHP脚本中,但我需要将其放入单独的JavaScript文件中并从 custom.js 调用此文件。
在 custom.js 中,我添加了以下行,其中包含名为 chiama-player.js 的文件到<head>
标记中:
var html_doc = document.getElementsByTagName('head').item(0);
var js = document.createElement('script');
js.setAttribute('language', 'javascript');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', "/wp-content/themes/Gleam/chiama-player.js");
html_doc.appendChild(js);
名为 chiama-player.js 的文件包含实例化jPlayer的代码:
$(document).ready(function() {
if(window.location.href=="http://www.ordinarypeopleofficial.com/#!/le-canzoni/" || window.location.href=="http://www.ordinarypeopleofficial.com/le-canzoni/"){
$("#jp_container_1").css( { 'display': 'block' } );
$("#jquery_jplayer_1").jPlayer( {
ready: function () {
$(this).jPlayer("setMedia", {
m4a: "http://www.ordinarypeopleofficial.com/wp-content/themes/Gleam/shakeit.m4a",
});
},
swfPath: "http://www.ordinarypeopleofficial.com/wp-content/themes/Gleam/jplayer",
supplied: "m4a"
});
}
else{
$("#jp_container_1").css( { 'display': 'none' } );
}
});
问题: 一切都适用于支持M4A的浏览器。
问题来自Firefox。 Firefox不支持M4A,因此需要Flash后备才能运行。当我尝试在Firefox上加载页面时,我看到swfPath
被正确识别(事实上,如果我改变路径并输入一些随机文本,我在 Net 小组)。
问题是请求GET Jplayer.swf
永远不会得到结果,并且在没有获取文件的情况下继续加载数小时。
答案 0 :(得分:0)
进入文件 custom.js ,在函数et_init_scripts()
的末尾,我执行了以下步骤: