1.解決 瀏覽器 返回按鈕不刷新的問題 window.onpageshow = function(event) { if (event.persisted) { window.location.reload() }};2.H5 中 JS 禁用安卓手機物理返回鍵 XBack = {}; (functi ...
1.解決 瀏覽器 返回按鈕不刷新的問題
window.onpageshow = function(event) {
if (event.persisted) {
window.location.reload()
}};
2.H5 中 JS 禁用安卓手機物理返回鍵
XBack = {};
(function(XBack) {
XBack.STATE = 'x - back';
XBack.element;
XBack.onPopState = function(event) {
event.state === XBack.STATE && XBack.fire();
XBack.record(XBack.STATE); //初始化事件時,push一下
};
XBack.record = function(state) {
history.pushState(state, null, location.href);
};
XBack.fire = function() {
var event = document.createEvent('Events');
event.initEvent(XBack.STATE, false, false);
XBack.element.dispatchEvent(event);
};
XBack.listen = function(listener) {
XBack.element.addEventListener(XBack.STATE, listener, false);
};
XBack.init = function() {
XBack.element = document.createElement('span');
window.addEventListener('popstate', XBack.onPopState);
XBack.record(XBack.STATE);
};
})(XBack); // 引入這段js文件
XBack.init();
XBack.listen(function() {});
3.解決移動端底部input被彈出的鍵盤遮擋問題
方法1、
Element.scrollIntoView(); // 讓當前的元素滾動到瀏覽器視窗的可視區域內
document.querySelector('#inputId').scrollIntoView();
方法2:
Element.scrollIntoViewIfNeeded();