function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kumar GKumar G 

How to show pop up window only once per user while login

I have written a VF page to show popup in home page , it will shown whenever user login to organization. my requirement is here is popup window should show only once per user while login.

I have refered many Jqurey examples but unfurnatly i am not able to figure it out , please find my following code and suggest me.
<apex:page >
 <html>
<head>
  <title></title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/start/jquery-ui.css" type="text/css" media="all" />
    <script src="/soap/ajax/28.0/connection.js" type="text/javascript"></script>
    <script type="text/javascript">
        function showAlert(){
            jQuery('h2').each(
                function(){
                    if(this.innerHTML == 'Announcements') 
                        this.style.display='none';
                }
            );
            sforce.connection.sessionId = '{!$Api.Session_ID}';
            sforce.connection.query("SELECT Id,Message__c FROM Announcement__c WHERE Display_This_Annoncement__c = TRUE",
                {
                    onSuccess: function(result){
                        var records = result.getArray("records");
                        var message = '';
                        for(var i=0; i<records.length; i++){
                            message = 
                                message +
                                '<b>Announcement ' + (i+1) + '</b><br/>' 
                                + records[i].Message__c + '<br/><br/>';
                        }
                        jQuery( "#message" ).html(message);
                        jQuery( "#dialog-message" ).dialog({
                            modal: true,
                            buttons: {
                                Ok: function() {
                                        jQuery( this ).dialog( "close" );
                                    }
                            }
                        });
                    },
                    onFailure : function(error) {
                        jQuery( "#message" ).html('Error: ' + error);
                        jQuery( "#dialog-message" ).dialog({
                            modal: true,
                            buttons: {
                                Ok: function() {
                                        jQuery( this ).dialog( "close" );
                                    }
                            }
                        });
                    }                
                }
            );            
        }
        showAlert();
    </script>
</head>
<body>
    <div id="dialog-message" title="Attention!">
        <div id="message"></div>
    </div>
</body>
</html>
</apex:page>

Thanks in advance..
Harish M 8Harish M 8
@Kumar G 
If user login first time to ur community and if you wanna show the popup, i mean only once per user when he login first time.
--> create a flag on user object (by default it is false)
--> show popup and set it to true once user login 
-->hide that popup if that flag is true


so once user login and see the popup that flag (in USER) will go into true

______________________________

if you wanna show everytime that user login
use some parameters while login then show popup if u have those parameters ... like

if u have custom login VF page and custom controller for that login page
User logged in and while redirecting to home page add some parameters in login controller (at home page link)

ask me if u have any queries...we did this scenario recently
 
Kumar GKumar G
Hi Harish,

Thanks for your quick response.

I have created flag in user object . i didn't understand the second point which you have mentioned.

If you have a sample code please share or suggest me on the following.
Harish M 8Harish M 8
Hi Kumar G

<apex page controller="your controller" action="">
----------
//use standard popup code
<apex:outputPanel id="popup" rendered="{!u.loginFlag==false}">
<apex:outputPanel id="popInnerOutputPnl" styleClass="customPopup" layout="block" >


 </apex:outputPanel> </apex:outputPanel>

</apex:page>

In your controller:
public class className{
public user u {get;set;}
 public className(){
 u=[select id,loginFlag from User id=:userinfo.getuserid()];}//constructor
public void userLoginTrue(){

//loginFlag is created by you (checkbox)
if(!u.loginFlag)
{
    u.loginFlag==true;
update u;

}

}
}

try this