我剛剛遇到一個外部JavaScript文件的奇怪問題。它在Edge和Chrome中完美運行,但在Firefox(51.0.1)中無法運行。外部Javascript不能在Firefox中工作
我有很多的腳本在頁面的機身底部,這樣
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/adblocker.js"></script>
<script>
$(document).ready(function() {
$('.dir_hotel').keyup(function(event) {
if (event.keyCode == 13) {
this.form.submit();
return false;
}
});
});
</script>
<?php if ($mobile_browser > 0) { ?>
<script>
/* MOBILE COLLAPSE MENU */
(function($) {
$.fn.collapsable = function(options) {
// iterate and reformat each matched element
return this.each(function() {
// cache this:
var obj = $(this);
var tree = obj.next('.nav');
obj.click(function(){
if(obj.is(':visible')){tree.toggle();}
});
});
};
})(jQuery);
$(document).ready(function(){
$('.slide-trigger').collapsable();
$(".slide-trigger").click(function(){
$('.slide-trigger').html($('.slide-trigger').text() == 'Collapse MENU' ? 'MENU' : 'Collapse MENU');
});
});
</script>
<?php }?>
</body>
的adblocker.js文件不能運行。我嘗試添加警報作爲.js文件的第一行,警報從不出現。我在瀏覽器中檢查了控制檯,顯示該文件未加載。
如果我
<script>
window.onload=function(){
var clientHeight = document.getElementById('travins').clientHeight;
if (clientHeight < 20) {
var node = document.getElementById("insnote");
node.innerHTML = "<a href='https://clkuk.tradedoubler.com/click?p=18211&a=1906311&g=232597' target='_blank'>Columbus Direct Travel Insurance</a>";
}
var clientHeight = document.getElementById('flights').clientHeight;
if (clientHeight < 50) {
var node = document.getElementById("flightnote");
node.innerHTML = "<a href='http://www.kqzyfj.com/click-7782323-11015988-1440520708000' target='_blank'>Skyscanner</a>";
}
var clientHeight = document.getElementById('carhire').clientHeight;
if (clientHeight < 20) {
var node = document.getElementById("hirenote");
node.innerHTML = "<a href='http://www.zestcarrental.com/click.php?adm=1018&adt=14' target='_blank'>Zest Car Rental</a>";
}
var clientHeight = document.getElementById('parking').clientHeight;
if (clientHeight < 20) {
var node = document.getElementById("parknote");
node.innerHTML = "<a href='https://clkuk.tradedoubler.com/click?p=20642&a=1906311&g=20842820' target='_blank'>Purple Parking</a>";
}
var clientHeight = document.getElementById('brittany').clientHeight;
if (clientHeight < 20) {
var node = document.getElementById("ferrynote");
node.innerHTML = "<a href='http://being.successfultogether.co.uk/click.asp?ref=731409&site=6792&type=b3&bnb=3' target='_blank'>Brittany Ferries</a>";
}
};
</script>
更換
<script src="js/adblocker.js"></script>
它完美的作品。
我試過js/adblocker.js,/js/adblocker.js和mydomain.com/js/adblocker.js,這沒有什麼區別。我也仔細檢查過這個文件實際上傳了,它是。我一定在做一些愚蠢的事情,但是什麼?
您是否在Firefox中安裝了adblocker擴展程序,該擴展程序正在檢測外部腳本名稱中的「ad」並將其阻止? – Joe
給那個男人一枚金牌!你在一個,喬。我只是重命名了這個文件,它直接運行。有一點重複檢查是絕對可以肯定的,但我認爲你已經得到了它。真正具有諷刺意味的是,因爲adblocker.js的全部目的是迴應adblocker的存在。非常感謝。 – TrapezeArtist