Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tracing links in a subframe window

Status
Not open for further replies.

Dev

Technical User
Jun 10, 2000
3
GB
I am writing an local browser app which loads local HTML pages into one of its subframes.&nbsp;&nbsp;I want to log any links which are clicked in the subframe and maybe do some processing on the link before it actually gets called.&nbsp;&nbsp;<br><br>Is there any way of intercepting links which are clicked in a subframe (or another window)?&nbsp;&nbsp;<br><br>I tried putting an onclick= for the window but altho it fired I couldnt find what link caused it and it also fires for clicking anywhere in the window.<br><br>Any help would be appreciated<br><br>Thanks
 
Dear Dev,<br><br>Here is how you would use the events in IE4 or 5 to obtain information about the anchor tag that was just clicked.<br>-------------------------------------------------<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript&gt;<br>&lt;!--<br><br>function linkInfo(){<br><br>var ele = window.event.srcElement;<br>alert( ele.id + &quot;\n&quot; + ele.getAttribute(&quot;href&quot;) +<br>&nbsp;&nbsp;&quot;\n&quot; + ele.getAttribute(&quot;target&quot;) +<br>&nbsp;&nbsp;&quot;\n&quot; + ele.innerText);<br>}<br>//--&gt;<br>&lt;/SCRIPT&gt;<br>&lt;/HEAD&gt;<br>&lt;BODY&gt;<br>&lt;a id=&quot;IBM&quot; <br>&nbsp;&nbsp;onclick=&quot;linkInfo()&quot;<br>&nbsp;&nbsp;href=&quot;ibm.com&quot; target=&quot;_blank&quot;&gt;Go to IBM&lt;/a&gt;&lt;br&gt;<br>&lt;a id=&quot;Microsoft&quot; <br>&nbsp;&nbsp;onclick=&quot;linkInfo()&quot;<br>&nbsp;&nbsp;href=&quot;microsoft.com&quot; target=&quot;_blank&quot;&gt;Go to MS&lt;/a&gt;&lt;br&gt;<br>&lt;a id=&quot;CNET&quot; <br>&nbsp;&nbsp;onclick=&quot;linkInfo()&quot;<br>&nbsp;&nbsp;href=&quot;cnet.com&quot; target=&quot;_blank&quot;&gt;Go to CNET&lt;/a&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>---------------------------------------------------<br><br>Hope this helps<br>-pete
 
Dear Pete <br><br>Thanks, that looks like just what I need. I will experiment and try to get familiar with the event model and let you know how I get on. <br><br>Is it possible to stop a traced link being jumped to if I need to? <br><br>Is there similar events for netscape? otherwise I will have to make my users run IE4 or 5 and some prefer netscape? <br><br>Thanks <br>Dev
 
Dear Pete<br>Ive been experimenting with you ideas and find that <br>1/&nbsp;&nbsp;I have a dilema - If I put a single Onclidk call into the head tag &lt;BODY onclick=&quot;return linkInfo()&quot;&gt;&nbsp;&nbsp;it works for all links but I will now have to distinguish between link and non link clicks!<br>2/&nbsp;&nbsp;if I put&nbsp;&nbsp;&nbsp;&quot;return false;&quot;&nbsp;&nbsp;at the end of the linkinfo fn I can stop the link being jumped to if I wish.<br><br>Im gradually getting there<br>Thanks<br>Dev
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top