How can I display a popup only on fresh form load, and not on reload?
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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:
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');
}
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.
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.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 13 guests