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

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
eedoh
Posts: 37
Joined: Tue Feb 11, 2014

24 Sep 2014

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

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

25 Sep 2014

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');
}

eedoh
Posts: 37
Joined: Tue Feb 11, 2014

25 Sep 2014

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.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 13 guests