Recent Topics

1 Jun 26, 2004 23:02    

Hi, my blog users often upload images with various size. how to limit image width becomes an issue. I have a phpbb running with the following in bbcode:

<img src="{URL}" onError="this.src='images/broken_images/broken_image.gif'" OnLoad="if(this.width > 640) {this.width=640}" style="cursor: hand" onClick="javascript:window.open('{URL}')" title="{URL}" border="0"/>

it defines allowed image width in dsplay well, and allow to open a window for an image to show its original size.

I inserted OnLoad="if(this.width > 640) {this.width=640}" into <img> tag to test its effect for my blog. it did work in backoffice, but not in viewer's window. this is one problem I have. another problem how to automatically add this code into <img> in both edit menu and file upload window. it is better to let CSS work this way. But I don't know CSS works with Onload such things. Anyone has any idea? Please let me know if my question is clear here. Thank you!

2 Jun 27, 2004 09:00

Any reason in particular why you're doing this in javascript, rather than CSS?

The CSS way:
Allow people to upload whatever size image they want.
Add this to the CSS file that you use for that skin:

img { max-width:640px; }

A cleaner way to do this with the DOM, if that's really how you want to do it, would be to add a function in the head segment to get the elements by type, and set the width. That way, there's no clutter in the XHTML, so it's much more readable and degrades better.

EDIT:
Oh, right, you want to be able to click on them to get the full image. Well, the javascript that you're adding to the IMG tags isn't going to do that, so there must have been some sort of function in the head to add an onClick event. Sorry that I'm not the DOM guru 'round these parts, or I'd give you more help.

3 Jun 27, 2004 18:53

thank you. I have tried your way(CSS way). It, again, worked in backoffice, I mean preview. then once I posted the image, and go back to blog, the image stretched to its full size. any thoughts. why backoffice works? i use custom skin (modified). so it has two columns.
thank you again.

6 Jun 28, 2004 06:00

Ah, I see... seems that it takes it fine in Mozilla, but IE is behind the times.

Anyone up for a little DOM scripting?


Form is loading...