单击 iframe 内的链接 [英] Click link inside iframe

查看:46
本文介绍了单击 iframe 内的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想借助 javascript 在 iframe 内的链接上单击,但这不起作用.index.php 在框架内加载 redirect.php 然后在 iframe 外创建按钮,点击链接 http://www.yoursite.com/.index.html:

<头><title>无标题页</title><script type="text/javascript">函数调用(){var allAnc = document.getElementById("d").contentDocument.getElementsByTagName("a");for (var i = 0; i < allAnc.length; i++) {如果 (allAnc[i].href.indexOf("http") > 0) {(allAnc[i]).click();休息;}}}<身体><input id="Button1" type="button" onclick="call()" value="button"/><iframe id="d" src="redirect.html" width="100%" height=700"></iframe></html>

redirect.html:

<头><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>重定向广告</title><script>function go_back() {window.history.go(-1);return false;}function ctu() {var link = document &&document.referrer;var esc_link = "";if (link) {var e = (window && window.encodeURIComponent) ?encodeURIComponent : escape;esc_link = e(link);}new Image().src ="/url?sa=T&url=" + esc_link + "&oi=unauthorizedredirect&ct=originlink";return false;}</脚本><body topmargin="3" bgcolor="#ffffff" marginheight="3"><div class="a"><div class="b"><font size="+1"><b>广告重定向</b></font>

<div class="c">&nbsp;La page que vous Consultiez essaie de vous rediriger vers <a href="/url?q=http://www.yousite.com/&amp;ei=2nPgT7uYJIP1-gb-kNiYDQ&sa=X&amp;oi=unauthorizedredirect&amp;ct=targetlink&ust=1340111586595170&usg=AFQjCNGP0YlzgPiD21g_9hQmBBb36l1THA>http://www.yoursite/a.com/<br><br>&nbsp;Si vous ne souhaitez pas Consulter cette page, vous pouvez <a href="#" onclick="return go_back();"onmousedown="ctu();">revenir à la page precédente</a>.<br><br><br>

</html>

解决方案

同源策略可防止您编写来自不同域的 iframe 脚本.

I want to click with the help of javascript on a link inside iframe, but this doesn't work. index.php load redirect.php inside frame then creat button outside iframe that click on the link http://www.yoursite.com/. index.html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
    <script type="text/javascript">
  function call() {
    var allAnc = document.getElementById("d").contentDocument.getElementsByTagName("a");
    for (var i = 0; i < allAnc.length; i++) {
    if (allAnc[i].href.indexOf("http") > 0) {
    (allAnc[i]).click();
    break;
    }
    }
  }
    </script>
</head>
<body>
    <input id="Button1" type="button" onclick="call()" value="button" />
<iframe id="d" src="redirect.html" width="100%" height=700"></iframe>
</body>
</html>

redirect.html:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Avertissement de redirection</title>
<script>function go_back() {window.history.go(-1);return false;}function ctu() {var link = document && document.referrer;var esc_link = "";if (link) {var e = (window && window.encodeURIComponent) ? encodeURIComponent : escape;esc_link = e(link);}new Image().src ="/url?sa=T&url=" + esc_link + "&oi=unauthorizedredirect&ct=originlink";return false;}</script>
</head>
<body topmargin="3" bgcolor="#ffffff" marginheight="3">
<div class="a">
<div class="b">
<font size="+1"><b>Avertissement de redirection</b></font>
</div>
</div>
<div class="c">
&nbsp;La page que vous consultiez essaie de vous rediriger vers <a href="/url?q=http://www.yousite.com/&amp;ei=2nPgT7uYJIP1-gb-kNiYDQ&amp;sa=X&amp;oi=unauthorizedredirect&amp;ct=targetlink&amp;ust=1340111586595170&amp;usg=AFQjCNGP0YlzgPiD21g_9hQmBBb36l1THA">http://www.yoursite.com/</a>.
<br>
<br>
&nbsp;Si vous ne souhaitez pas consulter cette page, vous pouvez <a href="#" onclick="return go_back();" onmousedown="ctu();">revenir à la page précédente</a>.
<br>
<br>
<br>
</div>
</body>
</html>

解决方案

The Same Origin Policy prevents you from scripting an Iframe from a different domain.

这篇关于单击 iframe 内的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆