Mal*_*lio 7 google-chrome ios chrome-ios
在一个文件中,我有
<a href="t2.html" target="_blank">go</a>
Run Code Online (Sandbox Code Playgroud)
在t2.html我有
<script>
document.write(window.opener);
</script>
Run Code Online (Sandbox Code Playgroud)
在iOS上的Safari上,在Mac上的Chrome上以及几乎所有其他浏览器上,它都会打印出[object Window]你想象的样子.
在iOS上的Chrome上,我得到了null.
如何进入打开此窗口的窗口?
此代码解决了您所讨论的问题(特别是针对Chrome ios不喜欢"弹出窗口"的问题),但是参考Paypal Adaptive Payments,它会打开"弹出窗口"并重定向到Paypal页面进行付款.
关键是你必须:
你想要/需要的主要是:
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();
}
Run Code Online (Sandbox Code Playgroud)
以下是您可以遵循的完整代码(忽略任何不适用于您正在做的事情).
<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>
Run Code Online (Sandbox Code Playgroud)
这似乎是一个更大的故事.在这里查看Bugtracker:
但似乎iframe可以处理父属性,所以也许您可以将应用程序从使用弹出窗口切换到使用叠加层.