在这个网站http://www.flatness.eu/test.html上,我有一个指向php文件的链接。
该文件包含一个用php编写的艺术作品。
该页面包含多层图像,用户单击这些图像可以逐个删除,直到页面为空。
有没有可能在php文件上的最后一次点击将用户直接链接回他们开始的html主页?
发布于 2013-06-12 20:28:49
链接到的php文件使用jQuery将一个名为houdini的类添加到隐藏的图像中。您可以更改click处理程序,以计算类不是houdini时留下的图像数量,然后重定向用户。
$(function() { //run when the DOM is ready
$(".image").click(function() { //use a class, since your ID gets mangled
$(this).addClass("houdini"); //add the class to the clicked element
if( $('.image:not(.houdini)').length == 1 )
{
// this is the last image, redirect user
window.location = 'http://yourpageurl.com';
}
});
});发布于 2013-06-12 20:27:56
PHP是服务器端的-如果你不在每次点击时都与服务器通信,它就不能知道用户何时点击了最后一张图片。
在你的代码中,你可以通过jquery向css添加类来隐藏图片,你可以用$('.houdini').length来计算有多少元素有这个类,并在此基础上通过javascript: window.location =“URL_HERE”调用重定向;
更简单的方法是倒计时--所以你可以让所有的图片都有像“显示”这样的类,然后点击do:
$(".image").on('click',function() {
$(this)addClass('houdini').removeClass('shown');
if ($('shown').length == 0) {
window.location = 'http://www.flatness.eu/home.html';
}
});发布于 2013-06-12 20:27:55
在PHP中:当为空时触发:
<?php
header("Location: http://www.example.com/");
exit;
?>编辑:实际上是用js删除图片,所以重新加载也应该由js触发!
$(function() { //run when the DOM is ready
$(".image").click(function() { //use a class, since your ID gets mangled
$(this).addClass("houdini"); //add the class to the clicked element
if($('.houdini').length == $(".image").length)
{
window.location.href="http://www.example.com/";
}
});
});https://stackoverflow.com/questions/17065403
复制相似问题