943,526 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 2nd, 2008
0

Re: get image size and how to make changes

I came up to this as for the final solution... Have fun!
This is a valid xHTML 1.0 Strict


javascript Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
  4. <head profile="http://www.w3.org/2005/10/profile">
  5. <title>Get The Image Size</title>
  6. <script type="text/javascript">
  7. /* <![CDATA[ */
  8. var img = document.getElementsByTagName('img');
  9. var links = document.getElementsByTagName('a');
  10. var imageWidth = [];
  11. var imageHeight = [];
  12. function myImage()
  13. {
  14. for ( var x = 0; img.length; x++ ) {
  15. img[x].id = 'image' + x;
  16. links[x].id = 'show' + img[x].id;
  17. imageWidth[imageWidth.length] = img[x].width;
  18. imageHeight[imageHeight.length] = img[x].height;
  19. links[x].style.visibility = 'hidden';
  20. if ( img[x].width > 300 ) { img[x].width = 300; }
  21. img[x].onmouseover = function(e) {
  22. e = e ? e : window.event;
  23. t = e.target ? e.target : e.srcElement;
  24. if (document.images && img && t.width < 300) { links['show'+t.id].style.visibility = 'visible'; links['show'+t.id].href = t.src; }
  25. }
  26. links[x].onclick = function() {
  27. for (var i = 0; i < this.id.length; i++) {
  28. var uri = this.href;
  29. var ids = this.id;
  30. var ref = ids.charAt(i); } this.href = 'javascript:void(0);';
  31. window.open(uri,target="_blank",'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,width=' + imageWidth[ref] + ',height=' + imageHeight[ref] + '\'');
  32.  
  33. }
  34. }
  35. }
  36. if (window.addEventListener)
  37. window.addEventListener('load',myImage,false);
  38. else if (window.attachEvent)
  39. window.attachEvent('onload',myImage);
  40. else if (document.getElementById)
  41. window.onload = myImage;
  42. /* ]]> */
  43. </script>
  44. </head>
  45. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  46. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  47. <body>
  48. <p><img src="image1" alt="image1" /><br />
  49. <a href="*">Image1</a></p>
  50. <p><img src="image2" alt="image2" /><br />
  51. <a href="*">Image2</a></p>
  52. <p><img src="image3" alt="image3" /><br />
  53. <a href="*">Image3</a></p>
  54. </body>
  55. </html>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Dec 2nd, 2008
0

Re: get image size and how to make changes

Oops! I forgot to change it! Try to see line#24
if (document.images && img && t.width < 300) it all means that if your images is less than or lower than 300pixed wide then the corresponding link for that specific image will show up. But what is if the images is greater the 300px then the that images should be converted at exact width of 300px and then show specific link for that image.
For that outcome simply change the above code to this
if (document.images && img && t.width > 300) dont forget to mark the thread solved. Good day to you...
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Dec 2nd, 2008
0

Re: get image size and how to make changes

Oops! I forgot to change it! Try to see line#24
if (document.images && img && t.width < 300) it all means that if your images is less than or lower than 300pixed wide then the corresponding link for that specific image will show up. But what you want is if the images is greater the 300px then that images should be converted at exact width of 300px and then show specific link for those images.
For that outcome simply change the above code to this
if (document.images && img && t.width > 300) dont forget to mark the thread solved. Good day to you...
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Dec 4th, 2008
0

Re: get image size and how to make changes

Hi Essential,

Thanks for This.

But still my problem is not solved......

I used above code

The changes done by me in above are:
1] Instead of
<img src="image1" OR src="image2" OR src="image3" alt="image1" />
i use actual filename as below
<img src="limits.gif" alt="image1" id="image1" /> and so on
I am using IE 6 SP 2 and FF 3.0
****************************
Now I am facing below problems:
1] Images having more than 300px width are showing as it is on HTML page. [instead of showing 300px in width on html page]
2] Links are generating to all images though they are less [i.e. below 300px width]
3] when click on <a> only goes to next page and not showing the image. [Not opening in another popup with image]

Please suggest where i am wrong and how can I overcome the same.

****************************

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head profile="http://www.w3.org/2005/10/profile">
<title>Get The Image Size</title>
<script type="text/javascript">
<!--
var img = document.getElementsByTagName('img');
var links = document.getElementsByTagName('a');
var imageWidth = [];
var imageHeight = [];
function myImage()
{
for ( var x = 0; img.length; x++ ) {
img[len].id = 'image' + x;
links[len].id = 'show' + img[x].id;
imageWidth[imageWidth.length] = img[x].width;
imageHeight[imageHeight.length] = img[x].height;
links[x].style.visibility = 'hidden';
if ( img[x].width > 300 ) { img[x].width = 300px; }
img[x].onmouseover = function(e) {
e = e ? e : window.event;
t = e.target ? e.target : e.srcElement;
if (document.images && img && t.width > 300) { links['show'+t.id].style.visibility = 'visible'; links['show'+t.id].href = t.src; }
}
links[x].onclick = function() {
for (var i = 0; i < this.id.length; i++) {
var uri = this.href;
var ids = this.id;
var ref = ids.charAt(i); } this.href = 'javascript:void(0);';
window.open(uri,target="_blank",'toolbar=no,scrollbars=no,location=no,status=no,menubar=no,width=' + imageWidth[ref] + ',height=' + imageHeight[ref] + '\'');
if (window.addEventListener)
window.addEventListener('load',myImage,false);
else if (window.attachEvent)
window.attachEvent('onload',myImage);
else if (document.getElementById)
window.onload = myImage;
}
}
}

-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
</head>
<body>
<p><img src="limits.gif" alt="image1" id="image1" /><br />
<a href="*">Image1</a></p>
<p><img src="after_controls_2.gif" alt="image2"  id="image2"/><br />
<a href="*">Image2</a></p>
<p><img src="pic23281.jpg" alt="image3"  id="image3"/><br />
<a href="*">Image3</a></p>
</body>
</html>

****************************
Please help.
****************************

cheers,
Mahesh
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mlohokare is offline Offline
22 posts
since Oct 2008
Dec 4th, 2008
0

Re: get image size and how to make changes

All of my codes is tested before released!
It's working nice with me, since am using Opera 9.6 -

Quote ...
Things gone bad in your code! From this line -->
javascript Syntax (Toggle Plain Text)
  1. /* if (img[x].width > 300) { img[x].width = 300px; -- to fix simply copy the code below... */
  2.  
  3. if ( img[x].width > 300 ) { img[x].style.width = '300px'; }
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Dec 8th, 2008
0

Re: get image size and how to make changes

Hi Essential,

Is there any way that can help me.

Please suggest.


Thanks,
Mahesh
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mlohokare is offline Offline
22 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Regarding XML convertion
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Help me ->very son->CheckBox





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC