当前位置:网站首页>tinymce.init()浏览器兼容问题
tinymce.init()浏览器兼容问题
2022-06-21 16:00:00 【静安书以沫】
tinymce.init()浏览器兼容问题
tinymce是一个富文本控件
问题一:在低版本谷歌浏览器等,会出现找不到 window.Promise.allSettled 方法的问题。
这里使用手动添加 allSettled方法 进行处理
这里还遇到另一个问题,
问题二:tinymce.init()方法是 异步 的。在未初始化设置值,会出现setContent方法找不到问题。
本想使用回调函数解决问题二,结果网上未找到能用的回调函数。
测试 init_instance_callback : “hidetinymce” 参数不可用
最终使用setTimeout(“setTinymce()”,300); 延时执行来解决的。
$(function () {
setPromiseAllSettled();
})
/**
* 兼容低版本浏览器处理
*/
function setPromiseAllSettled() {
var browserName = navigator.userAgent.toLowerCase();
if (/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)) {
window.Promise.allSettled = function(values){
function isPromise(x){
if((typeof x==='object' && x!=null) || typeof x==='function'){
if(typeof x.then =='function'){
return true;
}
}
return false;
}
return new Promise((resolve,reject)=>{
let arr = [];//收集传入的项运行结果
let times =0;//调用的次数和传入的参数个数一致的时候,resolve
function collectResult(val,key,obj){
arr[key] = obj;
if(++times === values.length){
resolve(arr)
}
}
for(let i=0;i<values.length;i++){
let value = values[i];
if(value&&isPromise(value)){
value.then((y)=>{
let obj = {status:"fulfilled",value:y}
collectResult(y,i,obj)
},(err)=>{
let obj = {status:"rejected",reason:err}
collectResult(err,i,obj)
})
}else{
let obj = {status:"fulfilled",value:value}
collectResult(value,i,obj)
}
}
})
}
}
//初始化tinymce控件
tinymce.init({
selector: '#tinymce',
menubar:false,
statusbar:false,
toolbar:false,
language: 'zh-Hans'
});
}
/**
*初始化完成之后设置值
*/
function setTinymce(inst) {
$("#tinymce").html(loadData);
tinymce.activeEditor.setContent(loadData);
}
function SetData(data) {
...
setTimeout("setTinymce()",300);
...
}
边栏推荐
猜你喜欢

Huawei (13) - route introduction

快来围观–TPT18新版报到

The release of autok3s v0.5.0 continues to be simple and friendly

Unittest框架的测试日志

Esp8266/esp32 get NTP time method through timelib Library

Unittest framework

重磅丨国内首份呈现数据库发展历程的图鉴正式发布!

Serious illness insurance covers serious illness. Which product is the best in the market? Please recommend it

IDC咨询:2022年中国关系型数据库软件市场,变革即将到来

网购网站(期末大作业)
随机推荐
我敢闯 我会创!第八届“互联网 +”大赛GaussDB命题开放报名啦!
Alibaba cloud server + pagoda panel + no domain name deployment web project
Unittest framework
d改进翻译
Luban developers' in-depth Forum - "insight into the new trend of the Internet of things" with Chengdu partners
Qtcreator error reporting solution
一个好产品应该具备的特征
接口自动化加解密
微信小程序-image加载图片工具中显示,真机中不显示
Advanced performance test series 3. performance index, reliability test, capacity test and performance test
I do 3D restoration for the aircraft carrier: these three details are shocking
qtcreator报错解决
Remote connection raspberry pie in VNC Viewer Mode
Test log of unittest framework
Standing at the digital tuyere, how can tooling enterprises "fly"
Ares阿瑞斯i质押LP挖矿众筹模式dapp智能合约定制
AutoK3s v0.5.0 发布 延续简约和友好
机器学习模型监控(Aporia)
Esp8266 / esp32 obtenir la méthode NTP time via la Bibliothèque timelib
Cisco(35)——BGP入门实验