簡體   English   中英

如何僅在index.html中顯示頁面加載彈出窗口

[英]how to show pageload popup only in index.html

$(function(){
var overlay = $('<div id="overlay"></div>');
overlay.show();
overlay.appendTo(document.body);
$('.popup').show();
$('.close').click(function(){
$('.popup').hide();
overlay.appendTo(document.body).remove();
return false;
});

$('.x').click(function(){
$('.popup').hide();
overlay.appendTo(document.body).remove();
return false;
});
});

這是我的JavaScript代碼。...jquery插件: http : //code.jquery.com/jquery-1.8.2.js

jsfiddle: http : //jsfiddle.net/7QA3p/

此彈出窗口適用於每個頁面的頁面加載。但是我只想顯示index.html的頁面加載

使用代碼檢查頁面是否為index.html,

 var pagePathName = window.location.href;
if (pagePathName.substring(pagePathName.lastIndexOf("/") + 1) == "index.html") {}

那么您可以顯示或不顯示彈出窗口,例如

$(function () {
    var pagePathName = window.location.href;
    if (pagePathName.substring(pagePathName.lastIndexOf("/") + 1) == "index.html") {
        var overlay = $('<div id="overlay"></div>');
        overlay.show();
        overlay.appendTo(document.body);
        $('.popup').show();
    }
}

您可以使用此條件來檢查:

if (document.location.pathname.substr(-11) === "/index.html") {
    //your code here
}

將QueryString(用作標識符)添加到您的URL中,如下例所示:

http://example.com/index.html?pop=1

$(function(){
   //check here
   var checkQString = window.location.search;
   if(checkQString.startsWith('?')) {
      alert("Open Pop up here");
   } else {
      alert("no pop up");
   }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM