开发者

Detect time on page with PHP?

Using开发者_JAVA百科 PHP, is there a way to get the time spent on a web page in realtime?

Basically I want to use an if statement that says, if the visitor is on the page for more than 1 minute, then do something.

What I actually want to use this for is for preloading images for the next page.

Maybe jQuery instead?


You'd need a client-side technology, namely javascript, to do it. With PHP being a server-side technology, there is no way for it to "initiate" the preloading of other images. Set a timer using JS to execute after 60s and then execute your image preloading code. This way there is no need to check a conditional. Don't forget to clear the timer though!


You can't use PHP to do this, unless they are physically going to another page themselves. jQuery can accomplish what you want, just grab the current time when the page loads and use setInterval for every 1000 milliseconds to increment the time by 1 second.

Then you can use that time variable for whatever you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜