How can I display a popup only on fresh form load, and not on reload?

rss

Posted by eedoh - Sep 24 ’14 at 02:42

Basically, what I'm trying to do is to have a popup displayed when user opens the form, and if they get a validation error or something, and form gets re-displayed, I need the popup not to show up again. Can this be done, and how.

 

Thanks

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 1 month 6 days
    #1 by Dmitry Kozlov Sep 25 ’14 at 02:28

    Hi,

    You can store last opened form (ID and ListID) in cookie and do not display popup message if the user opens the same form again. Here is the code:

    var key = "last_opened_form";
    var value = _spPageContextInfo.pageListId + GetUrlKeyValue('ID');
    
    if ($.cookie(key) != value) {
    	$.cookie(key, value);
    	alert('Popup message');
    }
    
  • eedoh
    Member
    Member for: 7 years 8 months 27 days
    #2 by eedoh Sep 25 ’14 at 10:26

    This works only the first time. If you open new form, close it and open again, there's no popup, and it should appear... I managed to adjust it to my needs though. This is what I've done with it...

     

    var key = "last_opened_form";

    var value = _spPageContextInfo.pageListId + GetUrlKeyValue('ID');

    var alertSpan = $( "span[role='alert']" );

     

    if ($.cookie(key) != value && alertSpan.length === 0) {

    $.cookie(key, value);

    alert('The next number is ' + number);  //number variable is initialized elsewhere.

    }

     

    window.onbeforeunload = handleExit;

    function handleExit()

    {

    if(alertSpan.length === 0){

    $.cookie(key, null);

    }

    }

     

    Thanks for the solution.

Displaying 1 to 2 of 2 messages