我在内部单页应用程序上使用带有 vue-stripe-elements-plus 的 Stripe Elements。由于在用户离开更改信用卡模块后无需保持 strip 代码运行,我想完全卸载 strip ,但这似乎并不那么容易。
在我将它卸载到组件的 destroyed
钩子(Hook)中并删除添加的 iframe 之后:
destroyed () {
this.$unloadScript('https://js.stripe.com/v3/');
//delete window.Stripe; // commented because this makes stripe add iframes twice
let stripeIframes = [
document.querySelectorAll('[name^=__privateStripeMetricsController]'),
document.querySelectorAll('[name^=__privateStripeController]'),
];
stripeIframes.forEach(iframes => iframes.forEach(iframe => {
iframe.parentNode.removeChild(iframe);
}));
},
由 Stripe 添加的 iframe:
一段时间后再次出现(其中之一):
似乎这个 iframe 是由 Stripe 的监听器重新创建的,这些监听器在消息事件上附加到窗口对象。我无法删除此监听器,因为处理函数位于 iframe 内的 iframe 中,因此浏览器不允许我访问其内部结构。
此外,此监听器正在向 Stripe 发出不需要的请求:
XHR finished loading: POST "https://m.stripe.com/4".
最佳答案
您可以使用setTimeout(destroyed, 1000)
关于javascript - 如何删除 Stripe 的 iframe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55119026/