将iFrame的值传递给父's php变量


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上没有任何东西被交互。我不能得到iFrames与JS小提琴工作,所以这里有更多的代码来帮助理解:父母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>");