Getting elements in a webpage / IE Context Menu.

Hi,
I am working on a vb6 application that collects info from a page and it utilizes a javascript to get it's values.

It is partially based on an example found online at the following URL:

http://www.freevbcode.com/ShowCode.asp?ID=4553

It uses an html file with a javescript to return values.

I am not familiar enough with javascript to properly alter this to provide the behavior I need, which is to return the images url, not the link.

Example:
With this app when an image is clicked it returns the images location which is what I want, however if the image is also a hyperlink, it returns the hyperlink.

The behavior I want is the imageurl (location) not the hyperlink it points to.

The javascipt in the html file is as follows:
<SCRIPT LANGUAGE="JavaScript">
//Gets the href for the right clicked link or image

var MyExt = new ActiveXObject("IEext.IEExtension");
if(MyExt)
      {
            var MyEvent = external.menuArguments.event;
            var MyDoc = external.menuArguments.document;

              var MySel = MyDoc.selection;
              var Rng = MySel.createRange();
              var MyStr = new String(Rng.text);
            MyExt.SelText = MyStr
            
            var ref = external.menuArguments.document.URL
            MyExt.PageURL = ref
            
            var MyElement = MyDoc.elementFromPoint(MyEvent.clientX, MyEvent.clientY);
            var MyAnchor = MyElement;
            var URL = "";
            while(MyAnchor.tagName!="A" && MyAnchor.tagName!="AREA" && MyAnchor.tagName!="HTML")
            {
                  MyAnchor=MyAnchor.parentElement;
            }
            if(MyEvent.type=="MenuExtUnknown" || MyEvent.type=="MenuExtImage" || MyEvent.type=="MenuExtAnchor")
            {
                  if(MyAnchor.tagName=="A" || MyAnchor.tagName=="AREA")
                  {
                  URL = MyAnchor.href;
                  MyExt.URL = URL;
                  MyExt.LinkType = "Link";
                  }
                  if(MyAnchor.tagName=="HTML" && MyElement.tagName=="IMG")
                  {
                  URL = MyElement.src;
                  MyExt.URL = URL;
                  MyExt.LinkType = "IMG";
                  }
            }
      
                  MyExt.ShowInfo();

      }
else
      {
            alert("An error occured!");
      }
</SCRIPT>

I hope I exaplained this clearly enough, wasn;t sure whether to post this in the VB area or Javascript area, but the VB side I get completely, it is the return from this javascript that I need to alter.

I thank you in advance.

flosoftAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

knightEknightCommented:
if what you are saying is that you always want the image url and not the anchor href, then this might do it:

          if(MyEvent.type=="MenuExtUnknown" || MyEvent.type=="MenuExtImage" || MyEvent.type=="MenuExtAnchor")
          {
           // commenting out href stuff
           //    if(MyAnchor.tagName=="A" || MyAnchor.tagName=="AREA")
           //    {
           //    URL = MyAnchor.href;
           //    MyExt.URL = URL;
           //    MyExt.LinkType = "Link";
           //    }
           //    if(MyAnchor.tagName=="HTML" && MyElement.tagName=="IMG")
               {
               URL = MyElement.src;
               MyExt.URL = URL;
               MyExt.LinkType = "IMG";
               }
          }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flosoftAuthor Commented:
I tried this and then if the image is also part of a link
example:

<a href="someurl"><img src="/images/someimage.gif"></a>

it returns nothing at all... unless I am missing something.

what I am after is in the above case, I would want "/images/someimage.gif"

Thanks..
0
flosoftAuthor Commented:
Hi,
Missed a comment line, it works...some of the time that way.
For example at amazon.com if you try it on the promotion item at top left, it does not work, but it does on individual item pages??

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ziffgoneCommented:
Here's my solution, doesn't use ActiveX though:

<head>
<script type="text/javascript">
function findSource(e){
     var evt = e ? e : window.event;
         if(evt.target){
                  var myEvt = evt.target;
                  if(myEvt.tagName == "IMG"){
                      alert('The Images Source is: '+myEvt.src);
                  }
                  else{
                  return false;
                  }
         }
         else if(evt.srcElement){
             var myEvt = evt.srcElement;
                  // alert(myEvt.tagName);
                  if(myEvt.tagName == "IMG"){
                      alert('The Images Source is: '+myEvt.src);
                  }
                  else{
                  return false;
                  }
         }
         else{
         return null;
         }
}
    var IE = document.all?true:false;
       if(!IE){
          window.captureEvents(Event.CLICK);
          window.onmousedown = findSource;
       }
       else{
          document.onmousedown = findSource;
       }
</script>
</head>
<body>
Normal Image:<br>
<img src="http://www.experts-exchange.com/images/indexLogoPerson_06.gif" width="228" height="107"><br><br>
Hyper-Linked Image:<br>
<a href="http://www.experts-exchange.com/" onclick="return false;"><img src="http://www.experts-exchange.com/images/indexLogoPerson_02.gif" width="228" height="107" border="0"></a>

Regards...
0
ziffgoneCommented:
Whup, that should have said:

window.captureEvents(Event.MOUSEDOWN);

not:
window.captureEvents(Event.CLICK);

Regards...

0
flosoftAuthor Commented:
Adding points so I can split them. knightEknight answer too care of most of it, and through reviewing the code submitted my ziffgone, I think I wil be able to alter it a bit further to get the desired result, my thanks to both of you!
0
flosoftAuthor Commented:
Hope splitting was ok with both of you, and I sincerly thank you for your time!
0
ziffgoneCommented:
No problem flosoft, thanks for the points.

 :o)

Regards...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.