繁体   English   中英

在iframe中点击链接

[英]Click link inside iframe

我想在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>

相同来源策略阻止您编写来自其他域的iframe脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM