Link to home
Start Free TrialLog in
Avatar of eladr
eladr

asked on

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?
Avatar of Batalf
Batalf
Flag of United States of America image

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
Avatar of eladr
eladr

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eladr

ASKER

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

10x
Avatar of eladr

ASKER

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;
Joining the handlers is done like this:

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

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