Jump to content

Recommended Posts

I have a site that logs a user in and does a db lookup to see if the user has acknowledged that they have read a file. If they have not they are sent to a page with links to the files which need to be read. Once they read the file and click the acknowledge link the php script adds this file name along with user name to a table named read. What I want to do is stop the user from navigating away from this page if they have not acknowledged that they read the files. How would I use the javascript onunload function and do an ajax request to check if they have read the files that need to be read. I am new to ajax so any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/267385-use-onunload-to-do-an-ajax-request/
Share on other sites

  • 2 months later...

I'm thinking you can't stop them from leaving because they can just close the window and open a fresh window, but aside from that if I came to your site and you tried to force me to read something that I didn't want to it would be my last visit to your site. A message or something telling me I need to read it is one thing, but trying to force me to read it is unacceptable and the attempt to hijack my browser and force feed content like that is likely to lose you a lot of users. Just my personal opinion on the matter.

All your check's to see if they read the file should be done server side.  As you've described it, someone could just disable javascript to bypass all your checks and use the site anyway.  What you need to do is in your server-side scripts after checking the login, check if they have read the required documents.  If not, redirect them to the page to read them where they can then click a button at the bottom of the page to acknowledge having read it.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.