gpt4 book ai didi

ios - window.opener 未在 iOS Chrome 中设置

转载 作者:可可西里 更新时间:2023-11-01 03:27:49 24 4
gpt4 key购买 nike

在一个文件中,我有

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

t2.html 我有

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

在 iOS 上的 Safari、Mac 上的 Chrome 以及几乎所有其他浏览器上,它都会像您期望的那样打印出 [object Window]

在 iOS 上的 Chrome 上,我得到 null

如何到达打开此窗口的窗口?

最佳答案

此代码解决了您正在谈论的问题(特别是针对 Chrome ios 不喜欢“弹出窗口”的问题),但引用了 Paypal Adaptive Payments,它会打开一个“弹出窗口”并重定向到 Paypal 页面进行付款。

关键是你必须:

  1. 启动窗口。直接从按钮/链接点击打开
  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();
}

这是您可以遵循的完整代码(忽略任何不适用于您正在做的事情)。

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

关于ios - window.opener 未在 iOS Chrome 中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14637937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com