Open popup when clicking on same Div, after popup has closed












1















I have a Div that should open up a popup with its innerHTML content. However, the click only works once on the same Div. I can click Div 2 and the popup will open, but I want to be able to open Div 1 after Div 1 has been clicked and closed.



Also, if I click the link inside the popup and close the window, Div 1 and Div 2 do not open up the popup anymore.



How to make it so the popup opens again with the content after clicking the same Div, after the popup has closed?



Pure javascript preferred



Minimum example: https://jsfiddle.net/ta4802/9x2Lg3wn/



<div class="m1" onclick="basicPopup('',this);">Text text text text
<p> <a href="http://stackoverflow.com">Link 1</a> </p>
</div>









share|improve this question























  • The problem would appear to be, when your popup closes, it doesn't notify the original window to set popupwindow to null.

    – Snowmonkey
    Nov 20 '18 at 18:40
















1















I have a Div that should open up a popup with its innerHTML content. However, the click only works once on the same Div. I can click Div 2 and the popup will open, but I want to be able to open Div 1 after Div 1 has been clicked and closed.



Also, if I click the link inside the popup and close the window, Div 1 and Div 2 do not open up the popup anymore.



How to make it so the popup opens again with the content after clicking the same Div, after the popup has closed?



Pure javascript preferred



Minimum example: https://jsfiddle.net/ta4802/9x2Lg3wn/



<div class="m1" onclick="basicPopup('',this);">Text text text text
<p> <a href="http://stackoverflow.com">Link 1</a> </p>
</div>









share|improve this question























  • The problem would appear to be, when your popup closes, it doesn't notify the original window to set popupwindow to null.

    – Snowmonkey
    Nov 20 '18 at 18:40














1












1








1








I have a Div that should open up a popup with its innerHTML content. However, the click only works once on the same Div. I can click Div 2 and the popup will open, but I want to be able to open Div 1 after Div 1 has been clicked and closed.



Also, if I click the link inside the popup and close the window, Div 1 and Div 2 do not open up the popup anymore.



How to make it so the popup opens again with the content after clicking the same Div, after the popup has closed?



Pure javascript preferred



Minimum example: https://jsfiddle.net/ta4802/9x2Lg3wn/



<div class="m1" onclick="basicPopup('',this);">Text text text text
<p> <a href="http://stackoverflow.com">Link 1</a> </p>
</div>









share|improve this question














I have a Div that should open up a popup with its innerHTML content. However, the click only works once on the same Div. I can click Div 2 and the popup will open, but I want to be able to open Div 1 after Div 1 has been clicked and closed.



Also, if I click the link inside the popup and close the window, Div 1 and Div 2 do not open up the popup anymore.



How to make it so the popup opens again with the content after clicking the same Div, after the popup has closed?



Pure javascript preferred



Minimum example: https://jsfiddle.net/ta4802/9x2Lg3wn/



<div class="m1" onclick="basicPopup('',this);">Text text text text
<p> <a href="http://stackoverflow.com">Link 1</a> </p>
</div>






javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 18:33









A AA A

114




114













  • The problem would appear to be, when your popup closes, it doesn't notify the original window to set popupwindow to null.

    – Snowmonkey
    Nov 20 '18 at 18:40



















  • The problem would appear to be, when your popup closes, it doesn't notify the original window to set popupwindow to null.

    – Snowmonkey
    Nov 20 '18 at 18:40

















The problem would appear to be, when your popup closes, it doesn't notify the original window to set popupwindow to null.

– Snowmonkey
Nov 20 '18 at 18:40





The problem would appear to be, when your popup closes, it doesn't notify the original window to set popupwindow to null.

– Snowmonkey
Nov 20 '18 at 18:40












2 Answers
2






active

oldest

votes


















1














So using the code from your fiddle, I changed two things: first, I moved the var inside the function (doesn't need to be global), and second, I added a popupwindow.onUnload handler:



popupWindow.onUnload = function(){
popupWindow = null;
}


Adding that, when the window closes, the variable is cleared. Which would affect your if(...) statement. :)



See it working here.






share|improve this answer
























  • So the var was global because I specifically do not want the Div to be clickable if the content is the same. Disregarding that, this solves problem 1, but not problem 2, where if I click the link inside the popup, then click the Div again, the content does not refresh to the innerHTML.

    – A A
    Nov 20 '18 at 21:08











  • SO, in case two, if the content of the popup changes, you need to listen for the popstate event. I think. stackoverflow.com/questions/3522090/…

    – Snowmonkey
    Nov 23 '18 at 21:34











  • Thanks for the answer. I did some digging on the popstate event on Mozilla Devs, and it looks like popstate pushState() method only works with same origin URLs, not external URLs (which is what I have), so I don't think this would work.

    – A A
    Nov 25 '18 at 4:04





















0














You just have to remove or comment these lines from your code:



if (popupWindow && popupWindow.document.body.innerHTML == t1.innerHTML) {
return false; //if equal do nothing
}


When you click the Div1 link for the first time the popupWindow variable gets set and its innerHTML its given by the Div1 innerHTML. If you click again the link in Div1 this condition meets and the function returns false.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399372%2fopen-popup-when-clicking-on-same-div-after-popup-has-closed%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    So using the code from your fiddle, I changed two things: first, I moved the var inside the function (doesn't need to be global), and second, I added a popupwindow.onUnload handler:



    popupWindow.onUnload = function(){
    popupWindow = null;
    }


    Adding that, when the window closes, the variable is cleared. Which would affect your if(...) statement. :)



    See it working here.






    share|improve this answer
























    • So the var was global because I specifically do not want the Div to be clickable if the content is the same. Disregarding that, this solves problem 1, but not problem 2, where if I click the link inside the popup, then click the Div again, the content does not refresh to the innerHTML.

      – A A
      Nov 20 '18 at 21:08











    • SO, in case two, if the content of the popup changes, you need to listen for the popstate event. I think. stackoverflow.com/questions/3522090/…

      – Snowmonkey
      Nov 23 '18 at 21:34











    • Thanks for the answer. I did some digging on the popstate event on Mozilla Devs, and it looks like popstate pushState() method only works with same origin URLs, not external URLs (which is what I have), so I don't think this would work.

      – A A
      Nov 25 '18 at 4:04


















    1














    So using the code from your fiddle, I changed two things: first, I moved the var inside the function (doesn't need to be global), and second, I added a popupwindow.onUnload handler:



    popupWindow.onUnload = function(){
    popupWindow = null;
    }


    Adding that, when the window closes, the variable is cleared. Which would affect your if(...) statement. :)



    See it working here.






    share|improve this answer
























    • So the var was global because I specifically do not want the Div to be clickable if the content is the same. Disregarding that, this solves problem 1, but not problem 2, where if I click the link inside the popup, then click the Div again, the content does not refresh to the innerHTML.

      – A A
      Nov 20 '18 at 21:08











    • SO, in case two, if the content of the popup changes, you need to listen for the popstate event. I think. stackoverflow.com/questions/3522090/…

      – Snowmonkey
      Nov 23 '18 at 21:34











    • Thanks for the answer. I did some digging on the popstate event on Mozilla Devs, and it looks like popstate pushState() method only works with same origin URLs, not external URLs (which is what I have), so I don't think this would work.

      – A A
      Nov 25 '18 at 4:04
















    1












    1








    1







    So using the code from your fiddle, I changed two things: first, I moved the var inside the function (doesn't need to be global), and second, I added a popupwindow.onUnload handler:



    popupWindow.onUnload = function(){
    popupWindow = null;
    }


    Adding that, when the window closes, the variable is cleared. Which would affect your if(...) statement. :)



    See it working here.






    share|improve this answer













    So using the code from your fiddle, I changed two things: first, I moved the var inside the function (doesn't need to be global), and second, I added a popupwindow.onUnload handler:



    popupWindow.onUnload = function(){
    popupWindow = null;
    }


    Adding that, when the window closes, the variable is cleared. Which would affect your if(...) statement. :)



    See it working here.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 '18 at 18:44









    SnowmonkeySnowmonkey

    3,00011012




    3,00011012













    • So the var was global because I specifically do not want the Div to be clickable if the content is the same. Disregarding that, this solves problem 1, but not problem 2, where if I click the link inside the popup, then click the Div again, the content does not refresh to the innerHTML.

      – A A
      Nov 20 '18 at 21:08











    • SO, in case two, if the content of the popup changes, you need to listen for the popstate event. I think. stackoverflow.com/questions/3522090/…

      – Snowmonkey
      Nov 23 '18 at 21:34











    • Thanks for the answer. I did some digging on the popstate event on Mozilla Devs, and it looks like popstate pushState() method only works with same origin URLs, not external URLs (which is what I have), so I don't think this would work.

      – A A
      Nov 25 '18 at 4:04





















    • So the var was global because I specifically do not want the Div to be clickable if the content is the same. Disregarding that, this solves problem 1, but not problem 2, where if I click the link inside the popup, then click the Div again, the content does not refresh to the innerHTML.

      – A A
      Nov 20 '18 at 21:08











    • SO, in case two, if the content of the popup changes, you need to listen for the popstate event. I think. stackoverflow.com/questions/3522090/…

      – Snowmonkey
      Nov 23 '18 at 21:34











    • Thanks for the answer. I did some digging on the popstate event on Mozilla Devs, and it looks like popstate pushState() method only works with same origin URLs, not external URLs (which is what I have), so I don't think this would work.

      – A A
      Nov 25 '18 at 4:04



















    So the var was global because I specifically do not want the Div to be clickable if the content is the same. Disregarding that, this solves problem 1, but not problem 2, where if I click the link inside the popup, then click the Div again, the content does not refresh to the innerHTML.

    – A A
    Nov 20 '18 at 21:08





    So the var was global because I specifically do not want the Div to be clickable if the content is the same. Disregarding that, this solves problem 1, but not problem 2, where if I click the link inside the popup, then click the Div again, the content does not refresh to the innerHTML.

    – A A
    Nov 20 '18 at 21:08













    SO, in case two, if the content of the popup changes, you need to listen for the popstate event. I think. stackoverflow.com/questions/3522090/…

    – Snowmonkey
    Nov 23 '18 at 21:34





    SO, in case two, if the content of the popup changes, you need to listen for the popstate event. I think. stackoverflow.com/questions/3522090/…

    – Snowmonkey
    Nov 23 '18 at 21:34













    Thanks for the answer. I did some digging on the popstate event on Mozilla Devs, and it looks like popstate pushState() method only works with same origin URLs, not external URLs (which is what I have), so I don't think this would work.

    – A A
    Nov 25 '18 at 4:04







    Thanks for the answer. I did some digging on the popstate event on Mozilla Devs, and it looks like popstate pushState() method only works with same origin URLs, not external URLs (which is what I have), so I don't think this would work.

    – A A
    Nov 25 '18 at 4:04















    0














    You just have to remove or comment these lines from your code:



    if (popupWindow && popupWindow.document.body.innerHTML == t1.innerHTML) {
    return false; //if equal do nothing
    }


    When you click the Div1 link for the first time the popupWindow variable gets set and its innerHTML its given by the Div1 innerHTML. If you click again the link in Div1 this condition meets and the function returns false.






    share|improve this answer




























      0














      You just have to remove or comment these lines from your code:



      if (popupWindow && popupWindow.document.body.innerHTML == t1.innerHTML) {
      return false; //if equal do nothing
      }


      When you click the Div1 link for the first time the popupWindow variable gets set and its innerHTML its given by the Div1 innerHTML. If you click again the link in Div1 this condition meets and the function returns false.






      share|improve this answer


























        0












        0








        0







        You just have to remove or comment these lines from your code:



        if (popupWindow && popupWindow.document.body.innerHTML == t1.innerHTML) {
        return false; //if equal do nothing
        }


        When you click the Div1 link for the first time the popupWindow variable gets set and its innerHTML its given by the Div1 innerHTML. If you click again the link in Div1 this condition meets and the function returns false.






        share|improve this answer













        You just have to remove or comment these lines from your code:



        if (popupWindow && popupWindow.document.body.innerHTML == t1.innerHTML) {
        return false; //if equal do nothing
        }


        When you click the Div1 link for the first time the popupWindow variable gets set and its innerHTML its given by the Div1 innerHTML. If you click again the link in Div1 this condition meets and the function returns false.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 18:46









        ednincerednincer

        718615




        718615






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399372%2fopen-popup-when-clicking-on-same-div-after-popup-has-closed%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith