Reputation: 3
Here is my Javascript code. How can I make it display only on the home page?
$(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();
});
});
Upvotes: 0
Views: 938
Reputation: 123
The solution is to add conditional statement just above var id = '#dialog';
. The steps:
location.href
Here is the concrete example:
$(document).ready(function() {
if (location.href !== "http://www.infoways.com.np/") { // Add correct protocol for your url
return;
}
var id = '#dialog';
...
Upvotes: 1
Reputation: 66560
you can add this check:
$(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
}
});
your code will be executed if url ends with www.infoways.com.np
or www.infoways.com.np/
Upvotes: 1