Firefox中的NS_ERROR_FAILURE,用于在隐藏的iframe中设置画布字体 [英] NS_ERROR_FAILURE in Firefox on setting font of canvas inside a hidden iframe

查看:390
本文介绍了Firefox中的NS_ERROR_FAILURE,用于在隐藏的iframe中设置画布字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用canvas创建文本编辑器.

I am trying to create a text editor using a canvas.

要将光标放置在正确的位置,我需要计算每个字符的宽度.

To place the cursor at the right position I need to calculate the width of every character.

在初始加载时,我正在缓存每个字符的宽度.

I am caching the width of each character on initial load.

在直接启动时在Firefox上运行良好,但在隐藏其父级的iframe中启动时抛出错误(NS_ERROR_FAILURE).

This works fine on Firefox when launched directly but throws an error (NS_ERROR_FAILURE) when launched inside an iframe whose parent is hidden.

我已经在此处的小提琴中缩小了此案的范围.

I've narrowed down this case in a fiddle here.

有人可以帮助我解决此问题的原因吗?

Can anyone help me out with the cause of this issue?

推荐答案

您不能将iframe设置为display:none.如果您确实认为您需要一个看不见的iframe,请可以这样做:

You can't have an iframe set to display:none. If you really think you need an invisible iframe you can do this:

.frame-wrapper {
  z-index: -1231231;
  position:absolute;
  top:0; left:0;
  height:1px; width:1px;
  opacity:0;
}

但是,如果您正在运行的是看不见的画布,则可以使用javascript来做到这一点.

But if all you're doing is running an invisible canvas you can do that in javascript.

这篇关于Firefox中的NS_ERROR_FAILURE,用于在隐藏的iframe中设置画布字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆