Page 1 of 1

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

Posted: 24 Sep 2014
by eedoh
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

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

Posted: 25 Sep 2014
by Dmitry Kozlov
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:

Code: Select all

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

if ($.cookie(key) != value) {
	$.cookie(key, value);
	alert('Popup message');
}

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

Posted: 25 Sep 2014
by eedoh
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.