For example, Lets say I have a flash swf game, and when users press connect they are assigned a random id that's then put into a mysql table. Then I have other users that connect and then can connect to these random ids. When users click disconnect i have the id taken out of the table that way when other people want to connect they dont get ids that arent active. is it possible that when a window is cl开发者_运维技巧osed to have it run a php script? so i can get it to clear their user id?
use onbeforeunload
var clicked = false;
document.onclick = function()
{
//alert(event.srcElement.tagName);
if(event.srcElement.tagName)
clicked=true;
}
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
} else if (window.sidebar) {
clicked= true;
} else {
if(window.opera && window.print) clicked= false;
}
</script>
<script>
function doUnload()
{
urlstring = "http://www.google.com/popup.php";// add popup url
window.open(urlstring,'mywin',"height=400px,width=500px,status=no,toolbar=no");
}
</script>
<body onbeforeunload="if(!clicked) doUnload(); ">
You could do this with a bit of Javascript in the HTML (outside of Flash). This example uses jQuery's .unload():
<script type="text/javascript">
$(window).unload(function() {
$.ajax({ url: "clear_user_id.php"});
});
</script>
精彩评论