2012-04-06 3 views
2

이전 페이지의 변수에서 정보 (문자열)를 추가하는 방법을 찾고있었습니다.이전 페이지에서 변수 추가 (텍스트 필드 지정)

지금까지 내가 아는 한 어떻게 든 자바 스크립트를 사용하여 가능해야합니다.

제대로 작동하기 위해 이전 ..

<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을 기억하고 새로운 팝업 창에 링크를 (열립니다 코드의 조각을 가져올 수 없습니다 페이지). 이 창에서 사람들은 와우 캐릭터와이 캐릭터가 속한 영역에 대한 정보를 삽입 할 수 있습니다. 그들이이 작업을 수행 한 후 사이트를 제출하면 블리자드 병기고에서 검색 한 아바타에 대한 URL이 표시됩니다. 팝업 페이지

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

코드 : 내가 코드 줄 필요 지금이 현재 코드

<?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 
     } 
} 
?> 

(2012년 7월 4일) 업데이트 :

$ 이미지 = "http://eu.battle.net/static-render/eu/". $ obj-> thumbnail;

창이 닫히거나 다른 제출 버튼을 누르는 것만으로 반환됩니다 (닫기 버튼에서 일어나는 것이 바람직 함). 그 중 하나가 일어날 때 그리고이 문자열이 점을 삽입 할 필요가 :

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

avatarurl라는 texbox을.

바라건대 여러분 중 누구라도이 작업을 수행하는 javascript를 수정하거나 만드는 방법을 알고 있기를 바랍니다. 내 PHP는 이미 심각하게 제한되어 있기 때문에 내 자바 스크립트 지식은 아무도 옆에 있습니다.

답변

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이 있고, 당신의 부모 문서에 입력 요소가 avatarurl의 ID를 가지고 있는지 확인해야합니다.

+0

클래스 이름이 'cancel_link'인 링크에 대해 이야기하고 있습니다. 해당 클래스 이름의 버튼을 의미 했습니까? 두 번째 질문 : 반환 된 값은 URL의 마지막 부분 일 뿐이므로 $ image를 반환하기가 쉽지 않습니까? 그 이후로 나는 완전한 URL을 즉시 가지고있다. – Anori

+1

네, 맞습니다. 내 솔루션을 업데이트 할 것입니다. – hohner

+0

유일한 질문은 'avatarurl'입니다. ID는 어떤 ID 번호를 찾을 수 없기 때문에 정확히 어떤 의미입니까? – Anori

0

그래서 검색을 시도한 후 @Jamie에게 감사드립니다. 나는 어디에서보아야하는지 알고있었습니다.

찾았습니다 http://www.codingforums.com/showthread.php?t=213298 그리고 이것이 마침내 성공한 것입니다.

<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"가 추가로 여는 PHP 페이지

제가 첨가. armory.php 페이지에서

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

내가는 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()" /> 

을 그리고 완벽했다.

제이미에게 도움을 주셔서 감사합니다.

관련 문제