jump to content

Satheesh Babu

Fixing the style tag for image height and width as done by DEC.

Microsoft's DHTML Editing Control (DEC) adds a style tag for images specifying height and width, if you use image handles to resize the image. I've seen these tags appearing only when the height is adjusted.

The problem is that this makes a mess of the page when viewed through Netscape.

The following Javascript function fixes that by taking the attributes from inside style tag. This however causes duplicate height and width attributes, but that is automatically fixed by DEC:

    function fix4NS(instr){
        var re  = /STYLE=\"WIDTH\s*:\s*(\d+)px;\s*HEIGHT:\s*(\d+)px;*\s*\"/gi;
        var re1 = /<A\s+href=".*?"\s*>\s*<\/A>/gi; // for taking out blank links
        /* changes width and height from style definitions
        to plain HTML that NS can understand.
        A troublesome output -
        <IMG style="WIDTH: 10px; HEIGHT: 10px" width=20 height=30>
          will be changed to
        <IMG width=10 height=10 width=20 height=30>
        DHTML editor takes care of the extra tags.. phew!
        instr=instr.replace(re1, "");
        return(instr.replace(re, "width=$1 height=$2"));