| | |
get image size and how to make changes
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I came up to this as for the final solution... Have fun!
This is a valid xHTML 1.0 Strict
This is a valid xHTML 1.0 Strict
javascript Syntax (Toggle Plain Text)
<?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"> /* <![CDATA[ */ var img = document.getElementsByTagName('img'); var links = document.getElementsByTagName('a'); var imageWidth = []; var imageHeight = []; function myImage() { for ( var x = 0; img.length; x++ ) { img[x].id = 'image' + x; links[x].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 = 300; } 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> </head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <body> <p><img src="image1" alt="image1" /><br /> <a href="*">Image1</a></p> <p><img src="image2" alt="image2" /><br /> <a href="*">Image2</a></p> <p><img src="image3" alt="image3" /><br /> <a href="*">Image3</a></p> </body> </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Oops! I forgot to change it! Try to see line#24
For that outcome simply change the above code to this
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... Oops! I forgot to change it! Try to see line#24
For that outcome simply change the above code to this
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... •
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
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.
****************************
****************************
Please help.
****************************
cheers,
Mahesh
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
All of my codes is tested before released!
It's working nice with me, since am using Opera 9.6 -
It's working nice with me, since am using Opera 9.6 -
•
•
•
•
Things gone bad in your code! From this line -->
javascript Syntax (Toggle Plain Text)
/* if (img[x].width > 300) { img[x].width = 300px; -- to fix simply copy the code below... */ if ( img[x].width > 300 ) { img[x].style.width = '300px'; }
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
![]() |
Similar Threads
- edge detection in image processing (Java)
- Link on Image (JavaScript / DHTML / AJAX)
- loading image using opengl?? (C++)
- Monitor makes pinging sound, image problems (Monitors, Displays and Video Cards)
- Image Resize (Graphics and Multimedia)
- CD Burning Error: Block size does not correspond to image length (Windows NT / 2000 / XP)
- Putting an image into a Tkinter thingy (Python)
- CSS - strech a background image? (Site Layout and Usability)
- Python and the JPEG Image File, Part 1, The Header (Python)
- Curved bottom half of image on flat screen monitor (Monitors, Displays and Video Cards)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Regarding XML convertion
- Next Thread: Help me ->very son->CheckBox
Views: 4751 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array autoplay beta blackjack boarder box browser captcha captchaformproblem cart close codes column css date debugger decimal dependent design developer dom download element embed enter error events firefox flash focus form frameworks game gears getselection google gwt gxt hiddenvalue highlightedword hint html ie7 iframe index java javascript javascripthelp2020 javascripts jquery jsp libcurl listbox maps marquee masterpage media menu mimic mp4 onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect safari scale scriptlets search security select size software solutions sources starrating synchronous toggle tweet unicode variables w3c web webkit webservice window windowofwords xml





