setTimeout(f,0) 等效吗?为什么它可以解决跨浏览器问题?

发布于 2024-12-21 05:28:30 字数 1383 浏览 2 评论 0原文

以下方法:

Init: function (selector, settings)
{
    setTimeout(function()
    {
        var s =
        {
            width: '100%',
            script_url: '/Content/Scripts/tiny_mce/tiny_mce.js',
            theme: "advanced",
            plugins: "autolink,lists,pagebreak,style,layer,table,paste,directionality,noneditable,visualchars,xhtmlxtras,template",
            theme_advanced_buttons1: "fontselect,fontsizeselect,|,bold,italic,underline,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_buttons4: "",
            theme_advanced_more_colors: false,
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "none",
            theme_advanced_resizing: false,
            convert_urls: !!$(selector).data("richEditor-ConvertUrls") // by default we don't convert urls
        };
        $.extend(s, settings);
        $(selector).tinymce(s);
    },0);
}

适用于所有浏览器, 由于某种原因,我需要对 firefox 进行 setTimeout(f,0) 调用,此方法在 MVC 上的 ajax 部分加载上调用,如果没有此调用,编辑器将在 firefox 上挂起并且分页(单击内容通常会导致异常)。通过电话,一切都很顺利。

我想知道如何避免这个 setTimeout 调用(通过其他一些解决方法),如果这不是一个选项,我想知道为什么。

我担心这可能不是这种情况下最干净的解决方案。

The following method:

Init: function (selector, settings)
{
    setTimeout(function()
    {
        var s =
        {
            width: '100%',
            script_url: '/Content/Scripts/tiny_mce/tiny_mce.js',
            theme: "advanced",
            plugins: "autolink,lists,pagebreak,style,layer,table,paste,directionality,noneditable,visualchars,xhtmlxtras,template",
            theme_advanced_buttons1: "fontselect,fontsizeselect,|,bold,italic,underline,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_buttons4: "",
            theme_advanced_more_colors: false,
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "none",
            theme_advanced_resizing: false,
            convert_urls: !!$(selector).data("richEditor-ConvertUrls") // by default we don't convert urls
        };
        $.extend(s, settings);
        $(selector).tinymce(s);
    },0);
}

works on all browsers,
for some reason, I need the setTimeout(f,0) call for firefox, this method is called on an ajax partial load on MVC, without this call, the editor hangs on firefox and the page breaks (clicking on stuff results on exceptions most often than not). with the call, everything works perfectly.

I was wondering how I could avoid this setTimeout call (through some other workaround), and if that wasn't an option I would like to know why.

I'm scared this might not be the cleanest solution for this case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離人涙 2024-12-28 05:28:30

这必然是一个时间问题。
DOMContentLoaded 上是否发生了其他事情,也许tinyMCE 或其他脚本也在该事件上运行了一些东西?
或者加载执行 document.write() 的脚本?

可能在加载时执行此函数会使问题消失。
如果是这种情况,那么您必须弄清楚问题发生时发生了什么,也许可以在 Firebug 中进行配置文件会话。

This is bound to be a timing issue.
Does anything else happen on DOMContentLoaded, maybe tinyMCE or another script also runs things on that event?
Or a script is loaded which executes a document.write()?

Probably executing this function on load makes the issues go away.
If that's the case than you have to figure out whats happening at the time the problems occur, maybe do a profile session in Firebug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文