2013-02-01 21 views
6

在一個文件中,我有window.opener在iOS版Chrome瀏覽器沒有設置

<a href="t2.html" target="_blank">go</a> 

t2.html

<script> 
document.write(window.opener); 
</script> 

在Safari瀏覽器在iOS上,並在Chrome的Mac和在幾乎每隔一個瀏覽器,就像你期望的那樣打印[object Window]

在iOS上的Chrome上,我收到null

我該如何到達打開此窗口的窗口?

+0

在這裏看到的 - https://code.google.com/p/chromium/issues/detail?id = 136610 – vsync

回答

5

這似乎是一個更大的故事。見錯誤追蹤系統在這裏:

http://code.google.com/p/chromium/issues/detail?id=136610&q=window.opener&colspec=ID%20Pri%20Mstone%20ReleaseBlock%20OS%20Area%20Feature%20Status%20Owner%20Summary

但似乎,彷彿I幀能夠處理父母的財產,所以也許你可以使用彈出窗口使用覆蓋切換您的應用程序。

+0

有更新。該問題已被修復.https://code.google.com/p/chromium/issues/detail?id = 136610#c57 – kane

7

此代碼解決了您所討論的問題(特別針對Chrome ios不喜歡「彈出窗口」的問題),但是參考了貝寶自適應付款,它打開「彈出窗口」並重定向到Paypal頁面進行付款。

的關鍵是,你必須:

  1. 啓動直接從一個按鈕/鏈接點擊的window.open
  2. 必須使用_blank作爲窗口中的「名稱」(而不是選擇自己)

你想/需要的主要事情是:

var win; 

//VERY IMPORTANT - You must use '_blank' and NOT name the window if you want it to work with chrome ios on iphone 
    //See this bug report from google explaining the issue: https://code.google.com/p/chromium/issues/detail?id=136610 
win = window.open(paypalURL,'_blank'); 

//Initiate returnFromPayPal function if the pop up window is closed 
if (win && win.closed) { 
    returnFromPayPal(); 
} 

以下是完整的代碼是Y你可以遵循(忽略任何不適用於你正在做的事情)。

<div> 
    <?php $payUrl = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay?expType=mini&paykey=' . $payKey ?> 

    <button onclick="loadPayPalPage('<?php echo $payUrl; ?>')" title="Pay online with PayPal">PayPal</button> 
</div> 
<script> 
    function loadPayPalPage(paypalURL) 
    { 
     var ua = navigator.userAgent; 
     var pollingInterval = 0; 
     var win; 
     // mobile device 
     if (ua.match(/iPhone|iPod|Android|Blackberry.*WebKit/i)) { 
      //VERY IMPORTANT - You must use '_blank' and NOT name the window if you want it to work with chrome ios on iphone 
       //See this bug report from google explaining the issue: https://code.google.com/p/chromium/issues/detail?id=136610 
      win = window.open(paypalURL,'_blank'); 

      pollingInterval = setInterval(function() { 
       if (win && win.closed) { 
        clearInterval(pollingInterval); 
        returnFromPayPal(); 
       } 
      } , 1000); 
     } 
     else 
     { 
      //Desktop device 
      var width = 400, 
       height = 550, 
       left, 
       top; 

      if (window.outerWidth) { 
       left = Math.round((window.outerWidth - width)/2) + window.screenX; 
       top = Math.round((window.outerHeight - height)/2) + window.screenY; 
      } else if (window.screen.width) { 
       left = Math.round((window.screen.width - width)/2); 
       top = Math.round((window.screen.height - height)/2); 
      } 

      //VERY IMPORTANT - You must use '_blank' and NOT name the window if you want it to work with chrome ios on iphone 
       //See this bug report from google explaining the issue: https://code.google.com/p/chromium/issues/detail?id=136610 
      win = window.open(paypalURL,'_blank','top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', location=0, status=0, toolbar=0, menubar=0, resizable=0, scrollbars=1'); 

      pollingInterval = setInterval(function() { 
       if (win && win.closed) { 
        clearInterval(pollingInterval); 
        returnFromPayPal(); 
       } 
      } , 1000); 
     } 
    } 

    var returnFromPayPal = function() 
    { 
     location.replace("www.yourdomain.com/paypalStatusCheck.php"); 
     // Here you would need to pass on the payKey to your server side handle (use session variable) to call the PaymentDetails API to make sure Payment has been successful 
     // based on the payment status- redirect to your success or cancel/failed page 
    } 
</script> 
0

如果要將值從子項傳遞給父項,請使用以下代碼。

添加以下代碼父頁面:

var hidden, state, visibilityChange; 
     if (typeof document.hidden !== "undefined") { 
      hidden = "hidden"; 
      visibilityChange = "visibilitychange"; 
      state = "visibilityState"; 
     } else if (typeof document.mozHidden !== "undefined") { 
      hidden = "mozHidden"; 
      visibilityChange = "mozvisibilitychange"; 
      state = "mozVisibilityState"; 
     } else if (typeof document.msHidden !== "undefined") { 
      hidden = "msHidden"; 
      visibilityChange = "msvisibilitychange"; 
      state = "msVisibilityState"; 
     } else if (typeof document.webkitHidden !== "undefined") { 
      hidden = "webkitHidden"; 
      visibilityChange = "webkitvisibilitychange"; 
      state = "webkitVisibilityState"; 
     } 

     // Add a listener that constantly changes the title 
     document.addEventListener(visibilityChange, function() { 

      if (localStorage.getItem("AccountName")) { 
       $("#txtGrower").val(localStorage.getItem("AccountName")); 
      } 

      if (localStorage.getItem("AccountID")) { 
       $("#hdnGrower").val(localStorage.getItem("AccountID")); 
      } 

      }, false); 

加入子頁以下(任何首選事件)

function CloseChildAndLoadValuesToParent() { 

       localStorage.setItem("AccountName", 'MyAccountName'); 
       localStorage.setItem("AccountID", 'MyAccountID'); 

       window.close(); 


      } 
相關問題