我使用不同的內容編碼具有多個頁面(索引到index.html)的網站,但是一個標題和單腳。問題是我將我的footer.js文件鏈接到所有頁面(考慮到它需要相同的代碼),但問題是它在加載多個頁面時同時加載。防止在所有索引頁面中運行js文件
這是一個jQuery彈出,所以當我點擊index.html中顯示出來,它也顯示在contact.html
我不想修改我的代碼爲每一個頁面,特別是因爲它之後會動態的。
因此,這裏是我的javascript:
//open popup
$('.cdv').on('click', function(event){
\t event.preventDefault();
\t $('.cd-popup').addClass('is-visible');
});
//close popup
$('.cd-popup').on('click', function(event){
\t if($(event.target).is('.cd-popup-close') || $(event.target).is('.cd-popup')) {
\t \t event.preventDefault();
\t \t $(this).removeClass('is-visible');
\t }
});
//close popup when clicking the esc keyboard button
$(document).keyup(function(event){
\t if(event.which=='27'){
\t \t $('.cd-popup').removeClass('is-visible');
}
});
//open popup
$('.pdq').on('click', function(event){
\t event.preventDefault();
\t $('#cd-popup-politique').addClass('is-visible');
});
//close popup
$('#cd-popup-politique').on('click', function(event){
\t if($(event.target).is('.cd-popup-close') || $(event.target).is('#cd-popup-politique')) {
\t \t event.preventDefault();
\t \t $(this).removeClass('is-visible');
\t }
});
//close popup when clicking the esc keyboard button
$(document).keyup(function(event){
\t if(event.which=='27'){
\t \t $('#cd-popup-politique').removeClass('is-visible');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
我不太瞭解設置。你渲染一個頁面是不同的HTML文件的組合,多次加載相同的腳本,或者你是否模擬地(?)加載不同的頁面(在不同的標籤頁或窗口中),每個頁面都有它們正確的html文件?在後一種情況下,我沒有看到一個頁面中的點擊如何在其他頁面中產生任何效果(因爲它們在不同的標籤頁/窗口中)。也許這是你使用「頁面」這個詞讓我困惑。 – trincot
這裏的交易: index.html>運行footer.js contact.html>運行footer.js dispo.html>運行footer.js ... footer.js>在所有連接(鏈接)到index.html文件 – Hatem
的所有頁面上運行的單個文件,當我點擊第一個選項卡上的鏈接(顯示彈出窗口)時彈出窗口也是在所有其他標籤中顯示 – Hatem