![](/img/trans.png)
[英]How do I make the 'me' element only show the first time you load the home page with javascript?
[英]How do i load javascript popup only in home page? It is displayed in all page
這是我的Javascript代碼。 如何使其僅顯示在首頁上?
$(document).ready(function() {
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("slow",0.9);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
您可以添加此檢查:
$(document).ready(function() {
if (window.location.match(/www\.infoways\.com\.np$/) || window.location.match(/www\.infoways\.com\.np\/$/)) {
var id = '#dialog';
// more of your code
}
});
如果網址以www.infoways.com.np
或www.infoways.com.np/
結尾,您的代碼將被執行
解決方案是在var id = '#dialog';
正上方添加條件語句var id = '#dialog';
。 步驟:
location.href
比較/檢查當前URL 這是具體示例:
$(document).ready(function() {
if (location.href !== "http://www.infoways.com.np/") { // Add correct protocol for your url
return;
}
var id = '#dialog';
...
將代碼放在首頁html中的<script>
標記中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.