检测页面访问时更改图像

我知道有一些问题:访问过,所以现在我正在寻找替代方案。 我想知道用户是否可以访问我网站上的某个页面,一旦他们返回主页,就会显示不同的图像。

更新:主页中有图像,当您点击一个图像时,它会更改为新图像,表示您已访问过该页面。 但是,如何检测您是否在该网站的另一页上,并且您在没有单击图像的情况下访问该链接? 我仍然希望事件触发更改。 这有可能吗?

    Test Page    

Image 1

Image 2

使用PHP会话它应该工作。

你可以拥有一系列图像源

  images = []; images[1] = "src of pic1"; images[2] = "src of pic2"; //you can have more links if you want size = images.length; rNum = Math.floor(Math.random()*size); document.getElementById("img").src = images[rNum]; 

您应该在访问该页面时设置会话cookie。

这是一个很棒的jQuery jQuery插件。

主页代码

 $(function(){ if($.cookie("interior_page_visited")){ //display new image } else { //display initial homepage image } }); 

内页代码

 $(function(){ //set cookie, expires when browser is closed $.cookie("interior_page_visited", true); });