1

DHL では、 http ://www.dhl.com/en/express/tracking.html のように、Web サイトでパッケージを追跡できます。追跡番号を入力すると、次のような新しいウィンドウが開きます: http://www.dhl.com/content/g0/en/express/tracking.shtml?brand=DHL&AWB= SOMENUMBER1234

今、私は自分のサイトでこの動作を模倣したいと考えています. 追跡番号を入力できるフォームがあり、DHL の URL が開きます。これは可能ですか?

4

2 に答える 2

2

Using the new URL you've mentioned in the comments (please also update your post), you can do this with JavaScript and with a redirect through your own server.

Depending on your server-side scripting language, you may have to handle the server part differently. The following example is for PHP:

Client HTML:

<form method="GET" action="dhl_redirect.php" id="myForm">
    <input type="hidden" name="id" value="" id='myId' placeholder="Enter tracking number" />
</form>

Client JavaScript:

(function(){
 var form=myForm;
 form.addEventListener('submit',function(evt){
   var dhlUrl="https://dhlforyou.nl/login/track/";

   var id=document.getElementById('myId');
   if(/^\d+$/.test(id.value)){
    if(myForm.target==='_blank'){
     window.open(dhlUrl+id.value);
    }else{
     location.href=dhlUrl+id.value;
    };

   evt.preventDefault();


 },false);
})();

Server:

<?php
 if(isset($_GET['id'])&&!is_nan(intval($_GET['id']))){
  $dhlId=$_GET['id'];

  header('Location: https://dhlforyou.nl/login/track/'.dhlId);//Redirect to DHL
  exit;//Skip the rest of the script

 }else{//ID not set or not a number

    header('Location: myHTMLform.htm');
 }
?>

If you want to have this form open in a new tab, just set the attribute target to _blank.

于 2012-06-06T16:15:56.717 に答える
2

はい、非表示の値とテキスト ボックスを使用して作成するだけです。

<form method="GET" action="http://www.dhl.com/content/g0/en/express/tracking.shtml">
    <input type="hidden" name="brand" value="DHL" />
    <input type="text" name="AWB" size="{LengthOfTrackingNumber" />
</form>
于 2012-06-06T14:57:35.060 に答える