问题
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.
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?
回答1:
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;
}
But if all you're doing is running an invisible canvas you can do that in javascript.
来源:https://stackoverflow.com/questions/48303223/ns-error-failure-in-firefox-on-setting-font-of-canvas-inside-a-hidden-iframe