2011-12-07 47 views
0

如何從iframe表單id檢索值,並將其調用到我的客戶端html。檢索iframe值到客戶端頁面

(客戶端HTML) sample.html

<head> 
    <script> 
     function alertThis(){ 
      alert(parent.myframe.formsubmit.a_token.value); 
     } 
    </script> 
</head> 

<body> 

    <iframe name = "myframe" src="http://domain.com/sample/index.php"> 
    <button onClick = "alertThis();">Click Here</button> 

</body> 

(服務器端PHP) 的index.php

<form name = "formsubmit"> 
     <input id = "a_token" value="<?php echo $_SESSION['user'] ?>"/> 
</form> 

,但它不返回任何。

回答

0

VAR DOC = window.frames分類[ 'myframe'] 。.document.getElementById( 'a_token')值; alert(doc);

試試這個。

0

試試這個codepeace

<iframe name="myframe" id="myframe" src="http://domain.com/sample/index.php"> 

function alertThis(){ 
    var content = window.frames['myframe'].document.forms['formsubmit'].elements['a_token'].value; 
    alert(content); 
} 

編輯

同樣的問題已經使用jQuery

Get radio value inside iframe

$('#myframe').contents().find('a_token').val() 
+0

仍然沒有工作。 –

+0

@RobinCarloCatacutan請立即嘗試,我必須努力。 –

+0

但仍然無法正常工作,我想我只能找到另一種方式來加載我的PHP使用JavaScript來獲取我的值存儲在PHP中。如果你碰巧知道一些想法,你可以借給一些嗎? XD –