1

There are already numerous questions about jQuery cookie popups, so no need to go into any detail about that functionality. What I want to know is if this is the only way jQuery can handle popups only once per user or a time-based popup per user. I.e. the popup loads when the user first comes to the site and then doesn't load again for a week.

I know there is IP validation, but can jQuery do IP validation and if so, can you point me to a resource? I've searched here for jQuery popup IP validation and so far I haven't turned up anything.

o_O
  • 5,527
  • 12
  • 52
  • 90
  • 1
    jquery has no access to network information. the server could send along the IP it saw with the page at generation time, but why bother? mobile users could potentially be hopping amongst multiple gateway IPs. just set a cookie and have jquery check that. – Marc B Jul 10 '13 at 18:11
  • lol, don't think of jquery as some magic thing that will do stuff for you. At the end of the day, much like `.Net`, it's just "pre-compiled code". In other words, it can't do anything JavaScript can't do, it just makes it easier to write JavaScript! – SpYk3HH Jul 10 '13 at 18:12
  • and what if there are multiple users on the same IP? – epascarello Jul 10 '13 at 18:13

3 Answers3

4

I've said it countless times before and I'll say it again: IPs are a data delivery mechanism, not an identification or authentication tool. IPs are not guaranteed to be unique or stable in any way and are entirely unsuitable for identifying individual users at one machine.

You need to store an identifier on the user's machine somehow to remember for that particular user what he did or didn't do. A cookie is the most obvious answer, local storage, WebDBs, Flash cookies etc. are alternative fallbacks.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • Well no s*** SpYk3HH. Thanks for your useless troll fodder. No one here has made any mention of "magic" other than you or relating jQuery to anything other than a tool for writing js. Thanks for wasting everyone's time. – o_O Jul 10 '13 at 18:46
  • @deceze, the only reason I'm exploring other options other than the cookie was the fact many users have their setting sto delete cookies when closing their browser. That would render saving the cookie useless and would load everything for them every single time. But thanks for the info. I know there may be more users on a single IP, but it really isn't necessary to get that detailed with who is getting it and who is not, the more important thing to me is not annoying te same individual at the cost of letting ten other people see it. – o_O Jul 10 '13 at 18:48
  • @o_O Well, look into storing the "cookie" any way you can. There are many ways to leave data on a users machine; I believe combining them all together is called a "permacookie"? I forgot the name, google for it. It's the only realistic choice. – deceze Jul 10 '13 at 19:37
  • Thanks. permacookie is not a term I was familiar with and sounds like something that might help. – o_O Jul 10 '13 at 19:48
1

I must agree with deceze, considering a company for example could use a single IP while 10+ computers are connected to the web through this IP-address. So if an employee would visit your website the other 9 won't get to see your pop-up because someone with the same IP already visited your website.

But regardless of this being the right approach or not, to get back at you´re question, I came across this SO answer:

How to get client IP address using jQuery

It looks relative easy to get a vistors IP address, even though you should consider you're dependent on a third party this way.

Community
  • 1
  • 1
sam
  • 330
  • 2
  • 7
0

This has more to do with an understanding of how web browsers work and less to do with JQuery. What you need is a way to identify a user. The easiest and most accurate way is a cookie. Something that only the user will have. Plus, you're trying to trying to do this on the client side. The only way for javascript to persist data across requests is via cookies, and for some browsers an Html 5 data persistance structure like IndexedDB.

If you can program on the server you can try to do IP lookups but you potentially get one identifier for multiple devices which can be multiple users. This is because it is common for multiple people to use the same IP (think about how many devices are connected to your home router). You can get more accurate by using the http header value for user-agent. These values are not accessible via javascript.

It may help you to get a better understanding of how http requests and responses.

bryjohns
  • 646
  • 4
  • 18