JS Redirection Mobileライブラリwritten by Sebastiano Armeli-Battanaを使用しようとしています。モバイル検出/リダイレクトとjQuery UIダイアログ
デフォルトではが自動的にになります。ユーザーがモバイルデバイスを使用していることが検出された場合はモバイルサイトにリダイレクトされます。これは嫌いな練習です。
私はユーザにへの機会を与えたいと思います。に同意します。 Sebastianoに感謝してbeforeredirection_callback
が含まれています。これを使用してダイアログに選択肢を提供します。問題のWebサイトはjQuery UIに多額の投資をしているので、jQuery UIダイアログを使用しようとしています。 jQuery Dialogには戻り値はありませんが、コールバックを実行できます。
私は、この問題は他のものよりも可変スコープであると考えています。誰にでも問題の解決策が見えますか? argsの値を親のコールバックに戻すにはどうすればよいですか?
events.js:
// declare namespace if not already defined
var RP = window.RP || {};
RP.events = {
DetectedSiteSelection: "RP.Detect.onDetectedSiteSelection"
};
detect.js:ページで
// declare namespace if not already defined
var RP = window.RP || {};
// route-manager.js
(function ($, undefined) {
var init = function() {
var mobileSelectorDialog = $('<div></div>')
.html("<p>We have detected that you are browsing our website using a mobile device.</p><p>Click 'Yes' to use our mobile site, or click 'No' to stay on the desktop site.</p>")
.dialog({
title: 'Do you want to use our mobile site?',
bgiframe: true,
autoOpen: false,
minHeight: 200,
width: 350,
modal: true,
closeOnEscape: false,
draggable: false,
resizable: false,
buttons: {
'Yes': function() {
$(this).dialog('close');
$(document).trigger(RP.events.DetectedSiteSelection, true);
},
'No': function() {
$(this).dialog('close');
$(document).trigger(RP.events.DetectedSiteSelection, false);
}
}
});
SA.redirection_mobile ({
mobile_url : "http://site.com/mobile/",
noredirection_param:"noredirection",
cookie_hours : "2",
beforeredirection_callback : (function() {
// open dialog
mobileSelectorDialog.dialog('open');
// this needs to return true or false to beforeredirection_callback
// but it doesn't work (scope issue??)
$(document).on(RP.events.DetectedSiteSelection, function (evt, args) {
return args;
});
// return true or false for this to work
})
});
};
RP.Detect = {
Init: init
};
return true;
})(jQuery);
:
// Mobile browser detection
RP.Detect.Init();
同僚はおそらく非同期の問題であると指摘しました。 JavaScriptの実行は、イベントハンドラが処理されるずっと前に 'beforeredirection_callback'を通過しています。 – Junto