Firefox - designMode: disable image resizing handles

寵の児 提交于 2019-11-28 20:43:52

Say you turn contentEditable on like this:

document.body.contentEditable = true;

All you have to do is turn it off for all (or some) images.

var imgs = document.getElementsByTagName("IMG");
for (var i = 0; i < imgs.length; ++i) {
    imgs[i].contentEditable = false;
}

This works fine for Firefox:

document.execCommand("enableObjectResizing", false, false);

For IE i've used:

image.attachEvent("onresizestart", function(e) { e.returnValue = false; }, false);

I think you'll find this much more acceptable. Seems to work in Firefox but I'm not sure about other browsers:

document.execCommand("enableObjectResizing", false, false);

It leaves the drag and drop ability intact.

Well, you cannot remove those resize handlers neither in Firefox nor IE... at least I couldn't find a solution.

At the end I managed that in Firefox by editing some configuration files from FF installation folder and we don't want to do that, right?

Anyway, if you want to disable resizing if images (but resize handlers will still be visible) just add some css style like:

img {
    width: auto !important;
    height: auto !important;
}

regards, Mihailo

Although the question was a long time ago. Every block element (div, img...) will be decorated with handles from FF. Test it:

<div id="myDiv" contenteditable="true"><p>Sample text!</p></div>

No handles, no resize etc.

<div id="myDiv" contenteditable="true"><p>Sample text!</p><img src="picture.jpg" /></div>

The image can be resized. So you have to explicitly call contenteditable="false" for every block elem you do not want to have handles, as nickf said already for the images.

Even more weird: assign "position:absolute" to any of your elements - even the parent div - and it has handles again.

I cannot comment and vote yet so... according to nmb.ten's answer, you have to use:

document.execCommand("enableObjectResizing", false, false);

But it works only after your content is filled in (I mean if you have to edit some text saved before).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!