H5 开发中常见的小问题

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();

上一篇:JDBC插入数据超长时无法自动截断问题


下一篇:移动端H5开发中的常见问题处理