...

View Full Version : Obtain or set the link on an image?



vkidv
08-18-2004, 07:12 PM
I think this is a stupid question or not possible..

...Is it possible to obtain/set the link of a picture?



<a href="http://www.website.com/"><img src="image.gif" width="32" height="32" border="0"></a>

As an example, How would i obtain 'http://www.website.com/' without adding anything to the img/link tag?

jamescover
08-18-2004, 09:56 PM
..Is it possible to obtain/set the link of a picture?

Obtaining a link and setting one are two different things...which do you want to do? :confused:


<a href="http://www.website.com/"><img src="image.gif" width="32" height="32" border="0"></a>

As an example, How would i obtain 'http://www.website.com/' without adding anything to the img/link tag?


When? When someone clicks on the image??? If so, what do you want to do with link afterward? You will get more responses, with better explanations... :thumbsup:


-james

sad69
08-18-2004, 09:57 PM
You might be able to do something with:


var a_tags = document.getElementsByTagName('A');
for(var i = 0; i < a_tags.length; i++) {
if(a_tags[i].firstChild.nodeName == 'IMG') {
alert('image link: '+a_tags[i].getAttribute('href'));
}
}


Untested, but that's the idea. I'm not sure how you're going to narrow down the specific image/link other than that though..

Why don't you want to include an ID attribute on either the A or the IMG? That would greatly simplify things as you can simply use document.getElementById() to acquire the exact link you want.

Hope that helps,
Sadiq.

Willy Duitt
08-18-2004, 10:18 PM
Why don't you want to include an ID attribute on either the A or the IMG? That would greatly simplify things as you can simply use document.getElementById() to acquire the exact link you want.

Loading someone else page into my iframe and then trying to change their link targets to point toward those I would prefer maybe....

.....Willy

sad69
08-19-2004, 01:24 AM
Loading someone else page into my iframe and then trying to change their link targets to point toward those I would prefer maybe....

.....Willy

But wouldn't that result in an Access Denied error? I don't think that you should be allowed to do this...

Sadiq.

Willy Duitt
08-19-2004, 07:31 AM
But wouldn't that result in an Access Denied error? I don't think that you should be allowed to do this...

Sadiq.

Yep, but most people do not consider that and spin wheels until they yield the temptation.... :)

.....Willy

vkidv
08-29-2004, 01:38 PM
Why don't you want to include an ID attribute on either the A or the IMG? That would greatly simplify things as you can simply use document.getElementById() to acquire the exact link you want.

Hope that helps,
Sadiq.

Sorry everybody who misunderstood me. What i forgot to mention is that this is not my website of any such and thus i cannot add identifications (i could use proxomitron but...) or names because this is client side.

I am playing with Menu Extensions in Internet Explorer and i was looking for a way to obtain the URL an image links/points to with a right click. I'll see and play around with that code to see if it works with a menu extension

If you want to know what Menu Extensions are - http://msdn.microsoft.com/workshop/browser/ext/tutorials/context.asp?frame=true

Again, I am sorry.

glenngv
08-30-2004, 07:12 AM
Try:

external.menuArguments.event.srcElement.href

where:

external.menuArguments - is the window object where the context menu was executed.

event.srcElement - the object that fired the event (<a> tag in your case)

href = the value of the href property of the link



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum