php AdminLTE JavaScript中的iFrame问题无法读取null的属性(阅读'autoIframeMode')

g6baxovj  于 2022-12-21  发布在  PHP
关注(0)|答案(1)|浏览(694)

即时通讯使用管理LTE免费引导管理模板的一个简单的网络应用程序。
在正常的浏览器窗口中一切正常。我通过iframe嵌入基于adminLTE的应用程序。
在iframe中嵌入adminlte html时,我经常遇到错误。错误消息:

Uncaught TypeError: Cannot read properties of null (reading 'autoIframeMode') IFrame.js:271
at e.t._initFrameElement (IFrame.js:271:45)
at S.fn.init.e._jQueryInterface [as IFrame] (IFrame.js:434:88)
at IFrame.js:445:27
at dispatch (jquery-3.6.0.min.js:2:43064)
at v.handle (jquery-3.6.0.min.js:2:41048)

它试图将css类iframe-mode附加到body标记(来自adminlte.js的代码)

_initFrameElement() {
    if (window.frameElement && this._config.autoIframeMode) {
      const $body = $('body')
      $body.addClass(CLASS_NAME_IFRAME_MODE)

已尝试按照文档关闭AdminLTE的autoiframe模式。https://adminlte.io/docs/3.1/javascript/iframe.html
在html标签中添加:

<script>  
$('.content-wrapper').IFrame({
  onTabClick(item) {
    return item
  },
  onTabChanged(item) {
    return item
  },
  onTabCreated(item) {
    return item
  },
  autoIframeMode: false,
  autoItemActive: true,
  autoShowNewTab: true,
  allowDuplicates: true,
  loadingScreen: 750,
  useNavbarItems: true
})  
</script>

这个jquery抛出了一个错误:未捕获引用错误:未定义$
如何关闭这种将iframe-mode类附加到body标记的操作?
(防止自动管理iframe模式)

wydwbb8l

wydwbb8l1#

要禁用此组件,您需要在加载模板js之前通过本地存储设置配置

localStorage.setItem('AdminLTE:IFrame:Options',JSON.stringify({autoIframeMode:false,autoItemActive:false}))

这将在插件初始化时加载:

static _jQueryInterface(config) {
    if ($(SELECTOR_DATA_TOGGLE).length > 0) {
      let data = $(this).data(DATA_KEY)

      if (!data) {
        data = $(this).data()
      }

      const _options = $.extend({}, Default, typeof config === 'object' ? config : data)
      localStorage.setItem('AdminLTE:IFrame:Options', JSON.stringify(_options))

      const plugin = new IFrame($(this), _options)

      $(this).data(DATA_KEY, typeof config === 'object' ? config : data)

      if (typeof config === 'string' && /createTab|openTabSidebar|switchTab|removeActiveTab/.test(config)) {
        plugin[config]()
      }
    } else {
      new IFrame($(this), JSON.parse(localStorage.getItem('AdminLTE:IFrame:Options')))._initFrameElement()
    }
  }

相关问题