2

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

据我所知,这应该可以以某种方式使用 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)。在这个窗口中,人们可以插入一些关于 WoW 角色和这个角色所在领域的信息。在他们执行此操作并点击提交后,该站点会显示从暴雪军械库中检索到的头像的 URL。

http://eu.battle.net/static-render/eu/(图像路径)

弹出页面的代码:更新了当前代码 (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->thumbnail;

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

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

texbox 称为 avatarurl。

希望你们中的任何人都知道如何修改或创建为您执行此操作的 javascript。由于我的 php 已经受到严重限制,而且我的 javascript 知识几乎没有。

4

2 回答 2

2

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

// 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的类名是其类名,并且父文档中的输入元素的 id 为avatarurl.

于 2012-04-06T00:13:30.037 回答
0

因此,在尝试搜索并感谢@Jamie 之后,我知道该去哪里找。

我找到了http://www.codingforums.com/showthread.php?t=213298 这终于奏效了。

在打开它的 php 页面上,我添加了:

<script type="text/javascript">

function open_pop(){
window.open('armory.php','AvatarArmory','height=510,width=350,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<html>
.....
<input type="button" value = "OpenArmory" onClick="open_pop()" />

并添加id="blogbox"到文本框的输入中。

<input type="text" class="textbox" name="avatarurl" size="45" value="{$avatarurl}" id="blogbox"/>

在 armoury.php 页面上,我使用 javascrip 函数添加了这个按钮:

<script type="text/javascript">

            function pops(avatar){
            textcontent=opener.document.getElementById("blogbox").value;
            opener.document.getElementById("blogbox").value = textcontent + " " + avatar;
            }
            </script>
            <input type="button" value = "Insert Avatar.." onClick="pops('<?php echo $image; ?>');window.close()" />

这非常有效。

谢谢杰米的帮助。

于 2012-04-07T14:20:38.653 回答