ブラウザでページから離脱する際にAjaxでデータを送信するイベントを実装したのですが、スマホ・タブレット(iOS)ではタブを閉じた際にもイベントを実行させるにはどうしたら良いでしょうか。
ご提示よろしくお願いいたします。
JavaScript
1var ua = navigator.userAgent; 2 if (ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0) { 3 $(window).on("pagehide",function(){ 4 Ajaxpost(); 5 },false); 6 }else{ 7 $(window).on("beforeunload", function() { 8 Ajaxpost(); 9 }); 10 } 11} 12 13function Ajaxpost(){ 14 var ua = window.navigator.userAgent.toLowerCase(); 15 if ( ua.indexOf("msie") != -1 ){ 16 $.ajax({ 17 type: "post", 18 url: "php/hoge.php", 19 data: { test: 'test' , test: 'test' }, 20 timeout: 10000, // 蜊倅ス阪�繝溘Μ遘 21 22 success: function(result, textStatus, xhr) { 23 24 }, 25 // 騾壻ソ。螟ア謨玲凾縺ョ蜃ヲ逅 26 error: function(xhr, textStatus, error) { 27 28 } 29 }); 30 }else{ 31 $.ajax({ 32 type: "post", 33 url: "php/hoge.php", 34 data: { test: 'test' , test: 'test' }, 35 timeout: 10000, // 蜊倅ス阪�繝溘Μ遘 36 async: false, 37 38 success: function(result, textStatus, xhr) { 39 40 }, 41 // 騾壻ソ。螟ア謨玲凾縺ョ蜃ヲ逅 42 error: function(xhr, textStatus, error) { 43 44 } 45 }); 46 } 47}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。