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?

3
  • 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
    Commented Jun 16, 2017 at 11:47
  • yes i read about that but i didnt get how to do with cookie,can u please help me? Commented Jun 16, 2017 at 11:52
  • can this is possible with login flow? any body know related to that..!! Any suggestion ?? Commented Jun 18, 2017 at 17:59

1 Answer 1

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++;
                    }
                }
            }
    }   
8
  • 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. Commented Jun 16, 2017 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
    Commented Jun 16, 2017 at 12:01
  • Is your requirement to show the popup after every login or only once in the lifetime of the user?
    – RedDevil
    Commented Jun 16, 2017 at 12:02
  • after every login once in the salesforce for all users. Commented Jun 16, 2017 at 12:11
  • Then session storage should work. Please try without clearing the browsing data
    – RedDevil
    Commented Jun 16, 2017 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .