[英]Pass value from iFrame to parent's php variable
我對JS不太滿意,我已經搜索了一個小時,但是找不到我可以更改的解決方案。 在我的父框架中,我有這個
<input type="hidden" name="starter_name_available" id="starter_name_available">
在我的iFrame中
$starter_name_available = "0";
( 0
可能是不同的值,具體取決於來自父級的輸入)現在,當用戶在父級上鍵入一些詳細信息時,iFrame會刷新,這將確定$starter_name_available
的值以及其他內容,我該如何傳遞$starter_name_available
回到它的父級嗎? 在iframe上沒有任何互動。 我無法讓iFrame與JS Fiddle一起使用,因此這里有更多代碼可幫助您理解:父級javascript:
function SLTUpdateIframe()
{
var first = document.getElementById("starter_first").value;
if (first == ""){
first = "xxx";
}
var concatString = "";
var url = concatString.concat("newcall/SLT/sltusercount.php?first=", first, "&last=", last);
document.getElementById('SLTiframe').src = url;
}
父html:
<iframe src="newcall/SLT/sltusercount.php?first=xxx&last=xxx" name="SLTiframe" id="SLTiframe" seamless width="650px" height="45px" scrolling="no" frameborder="0"></iframe>
<label for="starter_first" class="label">First name</label><br />
<input type="text" class="textbox" name="starter_first" id="starter_first" onkeyup="SLTUpdateIframe()" />
<input type="hidden" name="starter_name_available" id="starter_name_available">
iframe代碼:
<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<?
$first = "xxx";
if(isset($_GET['first'])){
$first = strtolower($_GET['first']);
}
$last = "xxx";
if(isset($_GET['last'])){
$last = strtolower($_GET['last']);
}
$account = ">".$first.".".$last."@";
//the > and the @ surrounding the name are there to ensure we are finding the whole name and not just a fragment
// for example if we search Joe.Blo it shouldn't respond that it's found that account because Joe.Bloggs exists
$userlist = file_get_contents('../../lists/aduserlist.php');
$userlist = strtolower($userlist);
if(strpos($userlist,$account) !== false) {
if(!($account == '>xxx.xxx@')){
$first = ucfirst(strtolower($first));
$last = ucfirst(strtolower($last));
$account = $first.".".$last;
echo("<font face='Verdana' color='#303030' size='3'>There is already a user account with the name ".$account." </font>");
echo("<font face='Verdana' color='#f56a00' size='2'><br>Please try a different name (e.g. Steven to Steve) or add a number (e.g. John Smith2)</font>");
$starter_name_available = "0";
}
}else{
if(!($account == '>xxx.xxx@')){
$first = ucfirst(strtolower($first));
$last = ucfirst(strtolower($last));
$account = $first.".".$last;
echo("<font face='Verdana' color='#303030' size='3'>The name ".$account." is available</font>");
$starter_name_available = "1";
}
}
?>
</body>
</head>
弄清楚了,最終,感謝那些看過的人,我在if / else語句的iframe中添加了這一行(更改每個val)
echo("<script>$(document).ready(function(){ $('#starter_name_available', window.parent.document).val('1');});</script>");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.