是否有可能在JS中有一个事件,当某个变量的值发生变化时会触发该事件?JQuery被接受了.
我有一个Flash游戏,我试图保存用户关闭浏览器选项卡时的状态.它使用以下jquery代码:
//Called from Flash when window closes
function sendRequest(url, params) {
$.ajax({
type: "POST",
async: false,
url: url,
data: params
})
}
$(window).unload(function() {
//Make Flash attempt to save the game when the window closes.
//Flash gets the necessary data and calls sendRequest()
document["flashGame"].saveBeforeUnload();
});
Run Code Online (Sandbox Code Playgroud)
我希望它能在所有浏览器中正常工作,但最重要的是Chrome(我们的用户中没有很多人拥有IE).
Flash正在调用sendRequest(在所有浏览器中,通过警报测试),所以我不相信问题来自Flash,但它可能会.