Jump to content

Disclaimer access control


A_tom
 Share

Recommended Posts

You can either use Javascript or PHP. If you haven't learned any of them, check the W3Schools tutorials.

I am somewhat familiar and when given some example code, I can usually adapt it to my needs. I'm just looking for an example of how to do it.The disclaimer I want people to have to see is about 250 words, so I need something that looks more like a web page than just a simple text box with a button.

Link to comment
Share on other sites

The question isn't how you want it to look, it's how you want it to act. Do you only want it to appear once for a particular user, or every time? If it appears every time then it's just a regular web page, maybe with a Javascript overlay to show the disclaimer over the actual page content. If you only want it to appear once then you can use cookies to keep track of the last time that computer was shown the disclaimer.

Link to comment
Share on other sites

The question isn't how you want it to look, it's how you want it to act. Do you only want it to appear once for a particular user, or every time? If it appears every time then it's just a regular web page, maybe with a Javascript overlay to show the disclaimer over the actual page content. If you only want it to appear once then you can use cookies to keep track of the last time that computer was shown the disclaimer.

I think the best would be to have the user only have to acknowledge the disclaimer once. I am sure there are examples of this here and other places, but in searching, I have been unable find what I'm looking for.

Link to comment
Share on other sites

I found this code which would appear to do what I want, except (in my browser, at least) the disclaimer page is blocked by my adblocker. How does one avoid this? The other problem is that the popup blocker can completely defeat the purpose of the cookie code? How does one get around that?

 

<script>function getCookie(NameOfCookie){    if (document.cookie.length > 0) {                  begin = document.cookie.indexOf(NameOfCookie+"=");           if (begin != -1) {                 begin += NameOfCookie.length+1;             end = document.cookie.indexOf(";", begin);      if (end == -1) end = document.cookie.length;        return unescape(document.cookie.substring(begin, end));    }   }  return null;}function setCookie(NameOfCookie, value, expiredays) {var ExpireDate = new Date ();ExpireDate.setTime(ExpireDate.getTime() + (360));  document.cookie = NameOfCookie + "=" + escape(value) +   ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());}function delCookie (NameOfCookie) {  if (getCookie(NameOfCookie)) {    document.cookie = NameOfCookie + "=" +    "; expires=Thu, 01-Jan-70 00:00:01 GMT";  }}function DoTheCookieStuff(){ visited=getCookie('visited'); if (visited==null)  {setCookie('visited','yes',365)MyWindow=window.open('Disclaimer.html'); }}</script>
Edited by A_tom
Link to comment
Share on other sites

Popup blockers exist to block calls to window.open that weren't initiated by something like the user clicking. You won't be able to use that. You could redirect the user, or the more modern way to do it would be to show the disclaimer in something like a lightbox that would just overlay on top of the rest of the page. There are several Javascript lightbox libraries out there to do the heavy lifting for that.

Link to comment
Share on other sites

I have been experimenting with a lightbox and it works well enough.

http://www.siftradingsystems.com/P15C2.html

 

However, I need to turn this off for some period of time some the user is not repeatedly confronted with the disclaimer. For this I would seem to need to use a cookie, but I cannot get the jquery.cookie plugin to do anything.

 

Here is some test code I've been working with. Any reference at all to $.cookie causes nothing to happen.

<!doctype html><html><head><meta charset="utf-8"><title>Lightbox 2</title><meta name="description" lang="en" content="testing" /><meta name="author" content="Lokesh Dhakar"><meta name="viewport" content="width=device-width"><link rel="shortcut icon" type="image/ico" href="images/favicon.gif" /> <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" /><link rel="stylesheet" href="css/lightbox.css" type="text/css"     media="screen" /><script src="http://code.jquery.com/jquery-latest.js"></script>  <script src="/js/jquery.cookie.js"></script> <script src="/js/lightbox.js"></script><script>if(typeof $.cookie('Cookie1') === 'undefined'){//if (1 == 1){ //no cookie $('document').ready(function(){$('#ele_id').trigger('click');var date = new Date();date.setTime(date.getTime() + (5 * 1 * 1000));$.cookie('Cookie1', 'Kooky'{ expires: date }); });}  //} else {// have cookie, do nothing// alert($.cookie('Cookie1'));//}</script></head><body><a id ="ele_id" href="img/Disclaimer.png" rel="lightbox" data-title="Disclaimer"></a><p>This is a test page.</p></body></html>
Link to comment
Share on other sites

It looks like you were missing a comma here

$.cookie('Cookie1', 'Kooky'{ expires: date });

And I'm not sure why you were checking for typeof, it should just be sufficient to pass the cookie name

if ($.cookie('Cookie1')) {  //cookie exists} else {  //cookie doesn't exist};

here are the docs

https://github.com/carhartl/jquery-cookie/tree/v1.4.1

 

Regarding references to $.cookie not doing anything, where you checking for errors in the console? What happens if you logged $.cookie? Are you sure the file was being loaded correctly?

Link to comment
Share on other sites

It looks like you were missing a comma here

$.cookie('Cookie1', 'Kooky'{ expires: date });

And I'm not sure why you were checking for typeof, it should just be sufficient to pass the cookie name

if ($.cookie('Cookie1')) {  //cookie exists} else {  //cookie doesn't exist};

here are the docs

https://github.com/carhartl/jquery-cookie/tree/v1.4.1

 

Regarding references to $.cookie not doing anything, where you checking for errors in the console? What happens if you logged $.cookie? Are you sure the file was being loaded correctly?

Thanks for your comments. I will try using jquery again and come back if I can't get it to work. Where was the comma supposed to be?

 

Nevermind, I finally got it to work. Here is my test page:

http://www.siftradingsystems.com/LightBoxTest.html

Edited by A_tom
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...