This is Function for background image.
$(document).ready(function() {
// // Set Background Image;
// var path = GetBasePath() + "images/bg.jpg";
$('body').css({
'background': 'url("' + GetBasePath() + '/images/bg.jpg") no-repeat center fixed',
'background-size': 'cover'
});
This is the function used for getting the base path.
function GetBasePath() {
// var pageUrl = document.URL;
// var pageUrlParts = pageUrl.split('/');
// var pageUrlPartsLength = pageUrlParts.length;
var neededUrl = '';
var trigger = true;
var pathArray = window.location.pathname.split('/');
neededUrl = window.location.protocol + "//" + window.location.host;
// neededUrl = pageUrlParts[0];
for (var i = 1; i < pathArray.length; i++) {
if (trigger) {
neededUrl = neededUrl + '/' + pathArray[i];
}
if (pathArray[i] == bookFolder) {
trigger = false;
}
};
// alert(neededUrl);
return neededUrl;
console.log(neededUrl);
Every thing works good but expect this extra basepath that i didn't want.
This is the inspect element code. And have extra basepath. Like ip-screen.html
<body style="background:
url("http://localhost/TeacherGuide/Human_Systems_Interactions/ip-screen.html/images/bg.jpg")
center center / cover no-repeat fixed;">
This will work fine if i remove ip-screen.html manually, but i don't know how to do this in js function. Need help. Any one?
As I Understand, please replace "ip-screen.html" from URL like below
var z="http://localhost/TeacherGuide/Human_Systems_Interactions/ip-screen.html/images/bg.jpg"
z=z.replace("/ip-screen.html/","/");
console.log(z);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.