3

i want whenever i Login salesforce there will be a popup that you are using chrome browser but i want this will popup only once and i tried this code

 <apex:page >

    <div id="browserid">

        <script type="text/javascript">

        txt = navigator.userAgent;
        var counter =0 ;
        if (txt.indexOf("Chrome")!=-1)
        {

                text="Chrome"
                window.onload = function(){
                    if(counter == 0){
                        window.alert("Currently you are using  " +text+ "",width=300,height=200);
                    counter++;
                    }
                }
            }
        }
</script>
    </div>
</apex:page>

but i am getting again and again popup. Please help me how to solve this problem?

  • 1
    You would need to store somewhere that this user has already had the popup. You could store this information in either a cookie, of in Salesforce. For most use cases i'm guessing a cookie would be the normal option. – Kasper Jun 16 '17 at 11:47
  • yes i read about that but i didnt get how to do with cookie,can u please help me? – sonam mittal Jun 16 '17 at 11:52
  • can this is possible with login flow? any body know related to that..!! Any suggestion ?? – sonam mittal Jun 18 '17 at 17:59
2

try session storage.

https://developer.mozilla.org/en/docs/Web/API/Window/sessionStorage

when someone logs in set the key

sessionStorage.setItem('Popupshown', 'true');

next time onwards check for this key

var popupshown = sessionStorage.getItem('Popupshown');

 if (sessionStorage.getItem("Popupshown") === null) {
sessionStorage.setItem('Popupshown', 'true');    
 txt = navigator.userAgent;
        var counter =0 ;
        if (txt.indexOf("Chrome")!=-1)
        {

                text="Chrome"
                window.onload = function(){
                    if(counter == 0){
                        window.alert("Currently you are using  " +text+ "",width=300,height=200);
                    counter++;
                    }
                }
            }
    }   
  • i tried this, and this is working also for me but for this need to clear my browsing data again and again whenever i login,that is not possible. – sonam mittal Jun 16 '17 at 12:00
  • it doesnt work that way since session storage only exists for the session and the moment you close the browser window this information is gone. check this out stackoverflow.com/questions/5523140/…. – RedDevil Jun 16 '17 at 12:01
  • Is your requirement to show the popup after every login or only once in the lifetime of the user? – RedDevil Jun 16 '17 at 12:02
  • after every login once in the salesforce for all users. – sonam mittal Jun 16 '17 at 12:11
  • Then session storage should work. Please try without clearing the browsing data – RedDevil Jun 16 '17 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.