2013-10-03 60 views
0

http://jsbin.com/ItaZAZu/1/edit抓鬥的IFrame源,則更新輸入文本框

在本質上鍵入時說bing.com在文本框中,然後一旦兵負荷點擊任何類似例如圖像的其他環節。當我通過contentWindow中的href改變位置時,我一直試圖更新iframe源代碼的輸入值,但沒有任何運氣。我所嘗試過的每一件事都沒有奏效,現在我無能爲力了。

任何幫助,非常感謝。

全碼

<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.min.js'></script> 
<style type="text/css"> 
span.style { 
    cursor: pointer; 
    font-family: Sans-Serif; 
    font-size: 1.5em; 
    font-weight: bold; 
    padding: 0 .5em; 
    color: #666; 
} 

span.style:hover { 
    color: #999; 
} 

span.style:active { 
    color: #000; 
} 

input#goto { 
    width: 80%; 
    font-family: Sans-Serif; 
    font-size: 1.25em; 
} 

iframe#browsensearch { 
    width: 100%; 
    height: 90%; 
} 
</style> 

<script type='text/javascript'> 
$(document).ready(function() { 
    $("#goto").click(function() { 
     $(this).select(); 
    }); 

    $("#forward").click(function() {  
     history.forward(); 
    }); 

    $("#back").click(function() { 
     history.back(); 
    }); 

    $("#goto").keyup(function(e) { 
     var val = $(this).val(), 
     sitesgohere = document.getElementById("browsensearch"); 

     sitesgohere.src = "http://" + val; 
    }); 
}); 
</script> 

<form name="sites" align="center"> 
    <span id="back" class="style">&lt;</span> 
    <span id="forward" class="style">&gt;</span> 
    <input id="goto" type="text" placeholder="http:// added by default" /> 
</form> 

<iframe id="browsensearch" src="http://theextinctionprotocol.wordpress.com/2013/10/01/large-fireball-seen-acoss-six-midwestern-states/" width="100%" height="100%" allowtransparency="true" frameBorder="0"> 
    Your browser does not support IFRAME's 
</iframe> 

回答

1

瀏覽器打開控制檯,並檢查錯誤消息,當您正在運行的樣品。

如果IFRAME內頁屬於除了由於父頁面不同的域來Same Origin Policy

不能訪問IFRAME的元件(包括 contentWindow