don't execute script if url contains #
i would like to execute the script below only if the url doesn't contains #
So don't execute script if url = http://win-e98sopqc735/Previsions/Lists/Prvisions/ViewParDateJour.aspx#ServerFilter=FilterField1
but execute if url = http://win-e98sopqc735/Previsions/Lists/Prvisions/ViewParDateJour.aspx
function addDays(dateObj, numDays) {
dateObj.setDate(dateObj.getDate() + numDays);
return dateObj;
}
function dateToShortString(date) {
var d = date.getDate();
var days = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var year = date.getFullYear();
var shortDateString = days + "/" + month + "/" + year;
return shortDateString;
}
var now = new Date();
var today = dateToShortString(now);
var tomorrow = dateToShortString(addDays(now, 1));
var nextWeek = dateToShortString(addDays(now, 8));
var url = location.pathname;
//Set today's date if url contains ViewParRubriqueJour.aspx and ViewParDateJour.aspx
if (url.indexOf('ViewParRubriqueJour.aspx') >= 0 || url.indexOf('ViewParDateJour.aspx') >= 0) {
jQuery("input[id*='ctl00_ctl00_ctl00']").val(today);
jQuery("input[id*='ctl00_ctl01_ctl00']").val(today);
}
//Set tomorrow's date if url contains ViewParDateDemain.aspx and ViewParRubriqu开发者_C百科eDemain.aspx
if (url.indexOf('ViewParDateDemain.aspx') >= 0 || url.indexOf('ViewParRubriqueDemain.aspx') >= 0) {
jQuery("input[id*='ctl00_ctl00_ctl00']").val(tomorrow);
jQuery("input[id*='ctl00_ctl01_ctl00']").val(tomorrow);
}
//Set 7 days date if url contains ViewParDate7.aspx and ViewParRubrique7.aspx
if (url.indexOf('ViewParDate7.aspx') >= 0 || url.indexOf('ViewParRubrique7.aspx') >= 0) {
jQuery("input[id*='ctl00_ctl00_ctl00']").val(tomorrow);
jQuery("input[id*='ctl00_ctl01_ctl00']").val(nextWeek);
}
Check for window.location.hash
,it will be #ServerFilter=FilterField1
or an empty string in case no hash is set.
Note that this will only work if there's something after the hashtag (#). If there's only a hashtag alone, you will have to parse window.location
.
The following code looks for any hash in the url.
if (!window.location.hash) {
// there is no hash, so execute stuff
}
If you want to look for a specific hash, use:
if (!window.location.hash == "specific-hash") {
// execute stuff
}
function addDays(dateObj, numDays) {
if(window.location.href.indexOf('#')) return; // this will stop the script
dateObj.setDate(dateObj.getDate() + numDays);
return dateObj;
}
function dateToShortString(date) {
var d = date.getDate();
var days = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var year = date.getFullYear();
var shortDateString = days + "/" + month + "/" + year;
return shortDateString;
}
....
....
精彩评论