Try our conversational search powered by Generative AI!

TinyMCE V2 - Remove the height and width attribute from images in editor.

Vote:
 

Hello,

I've been trying to programmatically remove the height and width attributes from the images via TinyMce

I've tried added a few things to to my initialization, but not of them seem to work.

It should be something simple like this:

 .AddSetting("extend_valid_elements", "img[class|src|id|alt]")

But that doesn't seem to remove the height and width attributes. 

invalid_elements only works on elements, not attributes.

image_dimensions removes the dimentions settings in the editor but not the code

 

#221575
Apr 21, 2020 19:50
Vote:
 

Hi,

I never tried this but have you tried adding following setting in the initialization module or tiny init method

 image_dimensions: false

https://www.imthi.com/blog/web/tinymce-remove-height-width-from-image.php

#221679
Apr 23, 2020 7:28
Vote:
 

Hi veckly,

It's strange, it seems like image_dimensions should work.

You could try something like this: https://gist.github.com/simshaun/7592631 (there may be a better example somewhere, this was just the first I found).

To use it you'd need to do something like:

.AddExternalPlugin("remove-img-dimensions", "/ClientResources/Scripts/tinymce/remove-img-dimensions.js")

Where that path is, of course, the path to your JS file.

Documentation is here: https://world.episerver.com/documentation/developer-guides/CMS/add-ons/customizing-the-tinymce-editor-v2/plug-ins/

#221703
Edited, Apr 23, 2020 16:01
Vote:
 

Hi Jake,

Logically it seems that image_dimensions: false would work.

But according to the documentation, and from what I've experenced, "This options allows you disable the image dimensions input field in the image dialog." It doesn't remove the attributes from the image tag in the code.   Also, it looks like this issue has been going on for a while now.

https://github.com/tinymce/tinymce/issues/2225

You can clear the dimentions in the input fields, but seeing that I managed hundreds of web authors having them all to remember to do this is an issue which can't be solved without a couple of  bottles of whatever poison you prefer.  

So clearing it out in the code is the best thing I can come up with and the plugin option may be the best.  I'll play around with that and see if I can find something that works.

I also need to add limits as to the images they can upload, and your blog posts have given me some pretty good advice and how to impliment that. 

#221710
Apr 23, 2020 18:52
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.