homerun
homerun

Reputation: 20765

JS: alert when clicking on a tag

i want to get alert when a A' tag inside the iframe is clicked , here is my code :

<Html>
<Head>
    <Title>change links</Title>
</Head>
<body>
    <iframe id="tab" src="http://www.site.com"></iframe>
    <script type="text/javascript">
          var tags = document.getElementsByTagName("a");
          tags.addEventListener("click", alert(""), false);
    </script>
</body>
</Html>

*the iframe isn't the same domain as where the script is running

why is't that working?

Upvotes: 0

Views: 79

Answers (1)

Tony Bogdanov
Tony Bogdanov

Reputation: 7686

Becouse this is considered a Cross-Site request or also called XSS attack. It is strictly PROHIBITED to read or modify in any way the content of an iframe on a different domain.

Furthur more frames are deprecated in the new HTML5 standart, so using them is discouraged.

Upvotes: 3

Related Questions