在这个网站http://www.flatness.eu/test.html我有一个php文件的链接。
该文件包含一个用php编写的艺术作品。
页面包含图像层,用户可以通过点击逐个删除,直到页面为空。
是否有可能使最后点击php文件链接的用户直接回到他们开始的html主页?
您链接到的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';
}
});
});
PHP是服务器端-它不能知道用户点击最后一张图片,如果你不与服务器通信每次点击
在你的代码中,你通过jquery添加类到css来隐藏图片,你可以计算有多少元素有这个类$('.houdini')。在此基础上,你可以通过javascript: window调用重定向。
从向上计数更容易倒数-所以你可以开始让所有的图像有一些类,如'显示',然后点击做:
$(".image").on('click',function() {
$(this)addClass('houdini').removeClass('shown');
if ($('shown').length == 0) {
window.location = 'http://www.flatness.eu/home.html';
}
});
in PHP: when empty:
<?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/";
}
});
});
链接HTML代码…
我猜你已经用HTML写了所有的代码,然后你只是把你的PHP代码和HTML代码混在一起。
,
<?php
//your php code
?>
或在页面中提供表单操作以提供主文件的路径。