-1

I have a popup that opens when you click a button. I want it to open automatically if somebody has been in the site for more than a minute. Right now I have this:

<script>
jQuery(document).ready(function () {

setTimeout(function() {
    $('#registerpopup').dialog('open');
}, 60000);

});
</script>

The problem is that only works after one minute in the page not on the whole site. How can I do this after 1 minute in the site? Thanks!

raygo
  • 1,348
  • 5
  • 18
  • 40
  • You mean across pages, like when user goes to a different page but stays on your website? – Selvakumar Arumugam Oct 30 '14 at 18:48
  • Yes, that's exactly it – raygo Oct 30 '14 at 18:49
  • Add this code to all pages & it will work for all pages. :) – Apul Gupta Oct 30 '14 at 18:49
  • 1
    @ApulGupta that clearly isn't going to do what he wants. – Kevin B Oct 30 '14 at 18:50
  • 2
    Whoever is voting this question down, could you please write a comment about why? Voting down doesnt help me nor the next person with this question – raygo Oct 30 '14 at 18:50
  • This feels like a valid question to my mind ... don't see reasons for down votes. – Kolban Oct 30 '14 at 18:51
  • Couple of ways you can achieve this, You could probably calculate the time stayed on each page and send the calculated `stayedTime` to server and on each page check the `stayedTime + currentPageTime >= 1 min` and show the popup. Other options: cookies, local storage. – Selvakumar Arumugam Oct 30 '14 at 18:51
  • Ignore the down votes, they just didn't take the time to understand the question. This seems to be an interesting task to do :) – Selvakumar Arumugam Oct 30 '14 at 18:52
  • Probably voting it down as being an awful idea as far as user interaction is concerned. Probably not the best use of downvotes, but it's our downvotes to use as we wish. – Kevin B Oct 30 '14 at 18:53
  • @KevinB I respectfully disagree as this is a valid requirement in many ways.. many sites would throw in a promotional advertisements when the user stays on their page for long time and this seems to be one of them. – Selvakumar Arumugam Oct 30 '14 at 18:56
  • Many sites do it, sure, i still consider it awful as an end user. Just like squeeze pages. They're incredibly annoying, but they're also very effective. But, that of course is not the point of my comment at all. Point is, people will use their downvotes as they see fit, and there's little to nothing that the avg user can do about it. – Kevin B Oct 30 '14 at 18:56
  • @KevinB I agree that it is "normally" an annoying practice but I could imagine paying for access to some information resource for an "hour" and want a popup telling me my time was nearly up (as an example). However I'd probably suggest this be cookie or localStorage based as opposed to browser instance context based. – Kolban Oct 30 '14 at 19:01
  • [This answer](http://stackoverflow.com/a/18763619/297641) may be helpful, you can find similar answer for the server technology you are using. – Selvakumar Arumugam Oct 30 '14 at 19:02

3 Answers3

0

When one shows a page, timers are in context of that page. When one navigates to a new page at the site, all logic that was previously running in the existing page is brought to a halt and the new page loaded.

For example, if you were looking at www.google.com and then went to www.bing.com, you would not want google to still be able to run logic in bing. The same holds true for navigating between pages at the same site (same domain). When a browser loads a page from a site navigating (normally) to another page tares down all logic in the original page.

One possible solution would be have an iframe covering your page and your navigation happens within the iframe. Then outside of the iframe would be one page and would be able to maintain context and code execution for the time spent at the site.

An alternate solution might be to maintain state in either cookies or localStorage and when each new page is reached, it could look at the previously saved values. This would mean that your timer would have to run on each page but could use the "site" stateful values to know for how long to pause.

Kolban
  • 13,794
  • 3
  • 38
  • 60
0

Use local storage for html 5: http://diveintohtml5.info/storage.html

Local storage is easy to hack but you just want to use it to calculate connection time and not for sensible information

Another approach could be using session variables if your website is made from server side.

-1

Use a iframe

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {

setTimeout(function() {
    alert("test");
}, 60000);
});

</script>
<iframe src="yoururl" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;">
  Your browser doesn't support IFrames
</iframe>`
lorigio
  • 89
  • 1
  • 3
  • 9