• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1635
  • Last Modified:

Detecting click on link inside iframe

i have a simple html page with an iframe.
Inside the iframe i have a page from external site which i cant change.
Can i detect an onclick event when someone clicked the link inside the iframe?
0
eladr
Asked:
eladr
1 Solution
 
BatalfCommented:
Sorry, you can't.

As long as the page is from an external site, there's nothing you can do to detect click on links or anything else.

Batalf
0
 
eladrAuthor Commented:
i was wrong.
the iframe is in my site but it contain a link from other site by js

<html>
<head>
<script>
</script>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<script type="text/javascript"
  src="http://server.com/show_links.js">
</script>

</body>
</html>
0
 
Michel PlungjanIT ExpertCommented:

<html>
<head>
<script>
</script>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function myclick() {
  alert(this.href+' was clicked')
}
function initPage() {
  for (i=0;i<document.links.length;i++) {
    document.links[i].onclick=myclick;
  }
}
</script>
</head>
<body onLoad="initPage()">
<script type="text/javascript"
  src="http://server.com/show_links.js">
</script>

</body>
</html>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
eladrAuthor Commented:
good.
im getting error when trying to pass parameters:
document.links[i].onclick=myclick(1);

10x
0
 
eladrAuthor Commented:
Also,the link already contains onclick
onclick='ha(2)'
so, i want to join the original onclick with the new onclick
like this
onclick = 'ha(2);myclick()";
i didnt succeded...
var OnClickStr = links[0].onclick;
links[0].onclick = MyLink; + ";" + OnClickStr;
0
 
ZvonkoSystems architectCommented:
Joining the handlers is done like this:

document.links[15].oldclick=document.links[i].onclick;
document.links[15].onclick=function(){this.oldclick();myclick(1)};

0
 
Michel PlungjanIT ExpertCommented:
You cannot pass parameters when you change the event handler the way I showed.
You need to do it the way Zvonko did. However that will add a new funtion to every link on the page

Michel
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now