【问题标题】:Click link inside iframe点击 iframe 内的链接
【发布时间】:2012-06-20 03:33:08
【问题描述】:

我想在 javascript 的帮助下点击 iframe 内的链接,但这不起作用。 index.php 在框架内加载redirect.php,然后在iframe 外部创建单击链接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>

【问题讨论】:

    标签: javascript onclick


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-05-23
      • 2011-02-13
      • 2017-10-29
      • 2018-12-12
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 2011-01-08
      相关资源
      最近更新 更多