Make async event synchronous in JavaScript

后端 未结 5 1763
迷失自我
迷失自我 2021-01-14 04:06

I\'m using the WPF 3.5SP1 WebBrowser control to display a page containing some javascript functions. My program then needs to invoke a javascript function which will make an

5条回答
  •  暖寄归人
    2021-01-14 04:50

    If I'm reading the question correctly, you're looking for a callback... so for example...

    function myscript()
    {
        some-async-function(
            params, //any params you plan to use
            function(result) {
               //handle the result here
            });
    }
    
    function some-async-function(retval,callback)
    {
        //assuming this really is an async function such
        //as an ajax call, etc...
        ...
    
        //work done, use the call back
        callback(retval);
    
    }
    

提交回复
热议问题