2015年8月24日 星期一

使用Javascript 將 主網頁資訊傳遞給 自身iframe內嵌網頁資料 iframe傳值的方法

網頁A (A.html):

 <iframe onload="setName('123')" name="history_page" id="history_page" src="B.html" width="240" height="130" scrolling="no" frameborder="0"></iframe>


function setName(str) {
       
        history_page.document.History_form.str_name.value = str;
    }


網頁B(B.html):


 <!--從主頁取得123值 -->
    <form action="abc.cgi" name="History_form" id="History_form" method="post">
        <input type="hidden" name="str_name" id="str_name" value="">
    </form>




從網頁A載入的時候就會一併將值透過iframe 的onload事件 將值傳遞個B.html 中的 str_name資料。 

沒有留言:

張貼留言