Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to resize this image

Status
Not open for further replies.

Bergkamp

Technical User
Feb 7, 2001
5
0
0
NL
My code:
<div id="Richtextcontent"><br>
<img src="/2-Bergkamw/FIN/Comp-reg.nsf/30ceb851136ec96cc12571e70032dff9/7d6c71e6ee0d6b22c1256e4b004c356f/Signature/15.2702?OpenElement&amp;FieldElemFormat=gif" width="784" height="142" alt=""><br>
</div>

This code is generated bij a webservice (IBM Lotus Domino webserver)The image cannot be modified in the database but need to be resized to max. 700 px.
With a stylesheet in Firefox it is no problem.

This works with Firefox;
#Richtextcontent img{
max-width: 700px;
}

However not with IE. How can I modify the width="784" parameter with javascript after loading the HTML-page.
I now you can substitute statements with javascript.

Thanks
W.
 
try this:
Code:
<script type="text/javascript">

function resizeImage() {
   document.getElementById("Richtextcontent").getElementsByTagName("img")[0].width = 700;
}

window.onload = resizeImage;

</script>

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
hmmm... something like:

Code:
function resize(imgId) {
    var max = 700;
    var i = document.getElementById(imgId);
    var w = parseInt(i.width);
    i.width = Math.min( w, max );
}

window.onload = function() {
    resize('myImg');
}



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
The final solution I came up with after all your input:
<script type="text/javascript">
var oH2s=document.getElementById("Richtextcontent").getElementsByTagName("img")[0];
if (oH2s.width > 700) {
document.getElementById("Richtextcontent").getElementsByTagName("img")[0].width = 700;
}
</script>

and it works like a charm.
Thanks guys.[thumbsup2]
 
you could cut down your code a bit making the following change (since you've already got it defined in a variable)
Code:
<script type="text/javascript">
var oH2s=document.getElementById("Richtextcontent").getElementsByTagName("img")[0];
if (oH2s.width > 700) {
   [!]oH2s[/!].width = 700;
}
</script>

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Unfortunalty some records holds more then one image. So finaly now all images will be resized when they are more then 700 px width;

<script type="text/javascript">
var oImgs=document.getElementById("Richtextcontent").getElementsByTagName("img");
var oTmp;
var oImg;
if(oImgs){
for(var i=0;i<oImgs.length;i++){
var oTmp=oImgs;
if(oTmp.width > 700){
oTmp.width = 700;}
}
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top