我有一种方法,单击按钮后会切换为现代版本:
Ext.beforeLoad = function (tags) {
var s = location.search, // the query string (ex "?foo=1&bar")
profile;
if (s.match(/\bclassic\b/)) {
profile = 'classic';
}
else if (s.match(/\bmodern\b/)) {
profile = 'modern';
}
else {
profile = tags.phone ? 'modern' : 'classic';
}
Ext.manifest = profile; // this name must match a build profile name
};
该代码在加载页面之前设置了配置文件。我使用方法添加参数:
onSwitchToClassicConfirmed: function (choice) {
if (choice === 'yes') {
var s = location.search;
// Strip "?modern" or "&modern" with optionally more "&foo" tokens following
// and ensure we don't start with "?".
s = s.replace(/(^\?|&)modern($|&)/, '').replace(/^\?/, '');
// Add "?classic&" before the remaining tokens and strip & if there are none.
location.search = ('?classic&' + s).replace(/&$/, '');
}
}
但是如果设备是手机或平板电脑,我想在现代和经典屏幕之间自动切换。
答案 0 :(得分:2)
看看Ext.os.deviceType属性,它包含当前设备的信息。
来自文档的说明:
当前设备的通用类型。
可能的值:
- 电话
- 平板电脑
- 桌面
使用该信息,您可以设置个人资料
var profile = Ext.os.deviceType === "Phone" ? "modern" : "classic";