Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Obtain or set the link on an image?

    I think this is a stupid question or not possible..

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

    Code:
    <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?
    Regards
    VKiDV

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ..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?

    <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...


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might be able to do something with:
    Code:
    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.

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sad69
    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

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Willy Duitt
    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.

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sad69
    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

  • #7
    Regular Coder
    Join Date
    Sep 2002
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/b...asp?frame=true

    Again, I am sorry.
    Last edited by vkidv; 08-29-2004 at 12:46 PM.
    Regards
    VKiDV

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts

    Taken from the Implementation Steps #2 in the link you provided

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •