JavaScript重定向它不是在服务器上工作,而是在本地主机上工作
JavaScript redirect it isn't working on server, but on localhost?
所以,我建立了一个小网站:http://rolandgroza.com/projects/tcsg/,但它似乎有一个问题,我在将文件移动到服务器之前没有遇到过。我通常在部署到服务器上之前在本地主机上进行测试,所以我只有在我这样做之后才看到问题。
你可以在源代码中看到我的JavaScript脚本,但我也把它放在这里:
$(document).ready(function() {
var header = $('body').find('header');
var footer = $('body').find('footer');
var badge = $('body').find('.badge-wrapper');
var logo_red = $(header).find('.logo a');
var navigation = {
home: $('body').find('.home'),
about: $('body').find('.about'),
services: $('body').find('.services'),
contact: $('body').find('.contact')
}
var container = {
home: $('body').find('.content-home-wrapper'),
about: $('body').find('.content-about-wrapper'),
services: $('body').find('.content-services-wrapper'),
contact: $('body').find('.content-contact-wrapper')
}
var home = {
form: $(container.home).find('.form-wrapper'),
galleries: $(container.home).find('.galleries-wrapper')
}
var about = {
notepad: $(container.about).find('.notepad-wrapper')
}
var services = {
minimum: $(container.services).find('.minimum-package'),
medium: $(container.services).find('.medium-package'),
featured: $(container.services).find('.featured-package')
}
var contact = {
notepad: $(container.contact).find('.notepad-wrapper')
}
var position = function (obj) {
return {
'top': (($(window).height() - $(obj).outerHeight()) / 2) + 'px',
'left': (($(window).width() - $(obj).outerWidth()) / 2) + 'px'
}
}
var current_page = function() {
var path = window.location.pathname;
var current_page = path.substring(path.lastIndexOf('/') + 1);
return current_page;
}
var curr_pag = current_page();
switch (curr_pag) {
case 'index.php':
$(navigation.home).addClass('selected');
break;
case 'about.php':
$(navigation.about).addClass('selected');
break;
case 'services.php':
$(navigation.services).addClass('selected');
break;
case 'contact.php':
$(navigation.contact).addClass('selected');
break;
default:
break;
}
$(logo_red).on('click', function() {
var page = current_page();
switch (page) {
case 'index.php':
$(home.form).removeClass('animated flipInX');
$(home.galleries).removeClass('animated flipInX');
$(home.form).addClass('animated fadeOutLeftBig');
$(home.galleries).addClass('animated fadeOutRightBig');
setTimeout(function(){
window.location.href = 'index.php';
}, 2000);
break;
case 'about.php':
$(about.notepad).removeClass('animated flipInX');
$(about.notepad).addClass('animated flipOutX');
setTimeout(function(){
window.location.href = 'index.php';
}, 2000);
break;
case 'services.php':
$(services.minimum).removeClass('animated flipInY');
$(services.medium).removeClass('animated flipInY');
$(services.featured).removeClass('animated flipInY');
$(services.minimum).addClass('animated fadeOutLeftBig');
$(services.medium).addClass('animated fadeOutDownBig');
$(services.featured).addClass('animated fadeOutRightBig');
setTimeout(function(){
window.location.href = 'index.php';
}, 2000);
break;
case 'contact.php':
$(contact.notepad).removeClass('animated flipInX');
$(contact.notepad).addClass('animated flipOutX');
setTimeout(function(){
window.location.href = 'index.php';
}, 2000);
break;
default:
break;
}
e.preventDefault();
})
for(var key in navigation) {
var object = navigation[key];
$(object).on('click', function(e){
var link = $(this).attr('href');
$(this).addClass('animated hinge');
var page = current_page();
switch (page) {
case 'index.php':
$(home.form).removeClass('animated flipInX');
$(home.galleries).removeClass('animated flipInX');
$(home.form).addClass('animated fadeOutLeftBig');
$(home.galleries).addClass('animated fadeOutRightBig');
setTimeout(function(){
window.location.href = link;
}, 2000);
break;
case 'about.php':
$(about.notepad).removeClass('animated flipInX');
$(about.notepad).addClass('animated flipOutX');
setTimeout(function(){
window.location.href = link;
}, 2000);
break;
case 'services.php':
$(services.minimum).removeClass('animated flipInY');
$(services.medium).removeClass('animated flipInY');
$(services.featured).removeClass('animated flipInY');
$(services.minimum).addClass('animated fadeOutLeftBig');
$(services.medium).addClass('animated fadeOutDownBig');
$(services.featured).addClass('animated fadeOutRightBig');
setTimeout(function(){
window.location.href = link;
}, 2000);
break;
case 'contact.php':
$(contact.notepad).removeClass('animated flipInX');
$(contact.notepad).addClass('animated flipOutX');
setTimeout(function(){
window.location.href = link;
}, 2000);
break;
default:
break;
}
e.preventDefault();
})
}
$(badge).hover(
function(){
$(this).addClass('animated swing');
},
function(){
$(this).removeClass('animated swing');
}
);
setTimeout(function(){
$(header).addClass('animated fadeInDown');
$(footer).addClass('animated fadeInUp');
$(badge).addClass('animated swing');
}, 1000);
setTimeout(function(){
$(home.form).addClass('animated flipInX');
setTimeout(function(){
$(home.galleries).addClass('animated flipInX');
}, 500);
}, 2000);
setTimeout(function(){
$(about.notepad).addClass('animated flipInX');
}, 2000);
setTimeout(function(){
$(services.minimum).addClass('animated flipInY');
setTimeout(function(){
$(services.medium).addClass('animated flipInY');
setTimeout(function(){
$(services.featured).addClass('animated flipInY');
}, 500);
}, 500);
}, 2000);
setTimeout(function(){
$(contact.notepad).addClass('animated flipInX');
}, 2000);
for(var key in container) {
var object = container[key];
var css = position(object);
$(object).css(css);
}
$('select').dropkick();
});
问题是,当单击其中一个菜单链接时,应该会发生一些动画,然后重定向到您单击的链接,带有window.location.href
,但它不起作用,几乎任何东西。
我无法说出问题是什么,所以我希望有人可以,因为在 XAMPP 本地主机上工作正常。
问题在于您询问当前页面,并且在主页上当索引不在 url 中时.php您缺少某些内容并且您的开关案例不起作用。在导航中的开关功能中添加一个没有页面或页面 == '' 的情况,这样它就会知道该怎么做。希望对您有所帮助!
相关文章:
- JavaScript 在本地主机中工作,但在托管时不能
- Jquery-ui 在 Firefox 的本地主机上工作正常,但在服务器上则不能
- Jquery Ajax在本地主机上工作,但拒绝在服务器上工作
- 引导在本地主机上工作,但不在联机服务器上工作
- 粘性导航栏在 jsfiddle 上工作,但在本地主机上不符合预期
- JavaScript重定向它不是在服务器上工作,而是在本地主机上工作
- 花式盒子在我上传到虚拟主机后不起作用,但在本地主机上工作
- 在实时服务器上未定义,但在本地主机上工作
- $(“Iframe”).contents()在本地主机上工作,但不能联机
- OAuth.popup()方法在live中不工作,在本地主机上工作
- Valence javascript客户端库在本地主机上工作吗
- 查询Meteor集合(在本地主机上工作,在服务器上失败)
- Webrtc应用程序在本地主机上不工作
- Ajax调用Php脚本以获取base64字符串中的图像,该字符串可在本地主机上工作,但不能从托管服务器中获取
- Wp_localize_script()仅在本地主机上工作
- jQuery路径点在本地主机上不工作
- Javascript不触发FB页面,在主机服务器上工作
- 返回错误;不工作在Firefox在远程主机,但工作在本地主机
- JS:从url获取主机名,正则表达式不工作
- TinyMCE不能在虚拟主机上工作