php - 将变量添加到上一页的(指定文本字段)

标签 php javascript jquery html

我一直在寻找一种方法来从上一页的变量中添加信息(字符串)。

据我所知,这应该可以通过某种方式使用 javascript 实现。

新的无法让旧的正常工作..

<script type="text/javascript">
function newPopup(url) {
    popupWindow = window.open(
        url,'popUpWindow','height=510,width=350,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<a href="JavaScript:newPopup('(url)');">Armory Avatar</a>

我有一段代码可以将链接打开到一个新的弹出窗口(它会记住上一页的 url)。 在这个窗口中,人们可以插入一些关于魔兽世界 Angular 色和这个 Angular 色所在领域的信息。在他们这样做并点击提交后,网站会显示从暴雪军械库中检索到的头像的 url。

http://eu.battle.net/static-render/eu/(imagepath)

弹出页面的代码:更新了当前代码 (7-4-2012)

   <?php
if (!isset($_POST['submit'])) { 
?>
<!-- The fill in form -->
<html>
<head>
<title>Armory Avatar</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Character Name:<input type="text" size="12" maxlength="50" name="cname"><br />
Realm Name:
<select name="rname">
<optgroup label="English Realms">
<option value="aerie-peak">Aerie-Peak</option>
<option value="agamaggan">Agamaggan</option>
<option value="aggramar">Aggramar</option>
etc etc etc.
</optgroup>
</select><br />
<input type="submit" value="submit" name="submit">
</form>
<?php
} else {  //If form is submitted execute this

    $charname = $_POST["cname"]; //input character name
    $realmname = $_POST["rname"]; //input realm name

    $charurl = urlencode(utf8_encode($charname)); //prepares character name for url usage
    $realmurl = 'http://eu.battle.net/api/wow/character/'.$realmname.'/';  //combines the basic url link with the realm name
    $toon = $realmurl.$charurl; //adds the charactername behind the realm url
    $data = @file_get_contents($toon); //retrieves the data from the armory api
        if ($data) {
            // if armory data is found execute this 

            $obj = json_decode($data); //converts the data from json to be used in the php code ?>
            <img src='http://eu.battle.net/static-render/eu/<?php echo $obj->thumbnail; ?>'> </img><br /> <?php //Is url link to image 
            $armoryname = utf8_decode($obj->name); //makes the name readable again
            echo "Name: " . $armoryname . "<br />";  //character name
            echo "Level: " . $obj->level . "<br />";  //character level
            echo "Achievement Points : " . $obj->achievementPoints . "<br />"; //Achievement Points
            if ( $obj->gender == 1 ){  //Deteremines the gender of the character
                echo "Gender : Female <br />" ;  //displays gender as female
            }else{
                echo "Gender : Male <br />" ; //dispalays gender as male
            } 
            $image = "http://eu.battle.net/static-render/eu/".$obj->thumbnail;
            ?>
            Image: <a href='http://eu.battle.net/static-render/eu/<?php echo $obj->thumbnail; ?>'> http://eu.battle.net/static-render/eu/<?php echo $obj->thumbnail; ?></a><br /> 


            <!--Button submit code-->

            <script type="text/javascript">
            $('button.cancel_link').click(function() {

            // Change the value of the input with an ID of 'avatarurl'
            // with the dynamic value given to you by the external JSON link

            window.opener.getElementById('avatarurl').value = '<?php echo $image; ?>';

            });
            </script>
            <input> <!-- The button here -->



        <?php   



        }
        else { // if armory data is not found execute this  ?>

            error code stuf
        }
}
?>

现在我需要这行代码:

$image = "http://eu.battle.net/static-render/eu/ ".$obj->缩略图;

在窗口关闭时返回,或者只需点击另一个提交按钮(最好在关闭按钮上发生)。当其中任何一个发生时,它需要将其插入到这个字符串中:

<input type="text" class="textbox" name="avatarurl" size="25" maxlength="100" value="{$avatarurl}" /></td>

名为 avatarurl 的文本框。

希望你们中的任何人都知道如何修改或创建一个 javascript 来为您做这件事。由于我的 php 已经受到严重限制,而我的 javascript 知识几乎为零。

最佳答案

您需要修改关闭弹出窗口的方式。尝试这样的事情:

// When a BUTTON with the class name 'cancel_link'
// is clicked, it activates the following

$('button.cancel_link').click(function() {

   // Change the value of the input with an ID of 'avatarurl'
   // with the dynamic value given to you by the external JSON link

   window.opener.getElementById('avatarurl').value = '<?php echo $image; ?>';

});

您需要确保您的关闭链接具有 cancel_link 作为其类名,并且您父文档中的输入元素具有 avatarurl 的 ID。

关于php - 将变量添加到上一页的(指定文本字段),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10037667/

相关文章:

javascript - 无法获得 Ajax 响应

javascript - Iframe 音频在滚动时淡入淡出

jquery - accordion-toggles - Jquery 活跃吗?

javascript - 如何在没有事件的情况下移动 div 的子级

使用 Jquery 装饰的 Javascript 表单验证

javascript - 来自 Laravel API 的 Vuejs 全局用户对象

php - 无法输出多维数组

javascript - 当表单具有 id ='submit' 值的提交按钮时,表单提交不起作用

javascript - 如何在客户端集合增长时立即响应地执行代码?

php - 如何使用 Objective-C 在 iOS 上执行相同的加密/解密 PHP 函数?