2012-06-19 8 views
1

Я хочу щелкнуть с помощью javascript по ссылке внутри iframe, но это не сработает. index.php load redirect.php внутри рамки, а затем кнопка creat вне iframe, которая нажимает на ссылку http://www.yoursite.com/. index.html:Нажмите ссылку внутри iframe

<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> 

ответ

1

Same Origin Policy мешает вам сценариев в Iframe из другого домена.

Смежные вопросы