问题:在微信上访问H5页面,其中在编辑器上完成编辑后失去焦点时操作页面回滚到顶部。
this.Editor = window.tinymce.init({
...this.DefaultConfig,
...this.config,
selector: `#${this.Id}`,
setup: (editor) => {
editor.on('blur', function () {
/**
**本来设想是直接使用编辑器本身的绑定事件来实现需求,
**后面发现移动端上没有触发编辑器上的blur事件
**下面的操作没有触发
**/
window.scrollTo(0, 0)
})
}
})
本身编辑器初始化完成之后就是一个iframe,在PC上测试可以正常触发编辑器上的blur事件,但是在IOS上测试就不起作用了,目前还没查到具体原因,因此只能换个思路来实现。
const self = this
this.Editor = window.tinymce.init({
...this.DefaultConfig,
...this.config,
selector: `#${this.Id}`,
setup: (editor) => {
editor.on('click', () => {
self.isClick = true
/**
**设置一个检测值,当第一次点击的时候赋值为true,
**然后通过监控这个值的变化使用原生js来为iframe绑定失去焦点的事件
**/
})
editor.on('blur', function () {
/**
**此时可以正常触发事件了
**/
window.scrollTo(0, 0)
})
}
})
主要是换种思路来解决问题