Calling a function defined inside jQuery ready from outside of it

后端 未结 3 888
你的背包
你的背包 2020-12-21 15:55

My aspx page:-

  
  

        
3条回答
  •  孤城傲影
    2020-12-21 16:37

    Declare your function like this inside the document ready:

    $(document).ready(function() {
    
        window.showMessage = function() {
            //...
        };
    
    });
    

    Then you should be able to call it from the other document like this:

    window.opener.showMessage();
    

    And because it's in the global scope, you can call it from within the main document just by calling

    showMessage();
    

提交回复
热议问题