admin管理员组文章数量:1435859
I'm using Stripe Elements with vue-stripe-elements-plus on internal single page app. As there is no need to keep the stripe code running after user leaves change credit card module I want to unload Stripe pletely but it doesn't appear to be that easy.
After I unload it in ponent's destroyed
hook and remove added iframes:
destroyed () {
this.$unloadScript('/');
//delete window.Stripe; // mented 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);
}));
},
iframes which were added by Stripe:
are reappearing again after a while (one of them):
Seems like this iframe is recreated by Stripe's listeners which were attached to window object on message event. I'm unable to remove this listener because the handler function is located in an iframe which is inside iframe, so the browser won't let me access its internals.
Moreover, this listener is making unwanted requests to stripe:
XHR finished loading: POST ";.
I'm using Stripe Elements with vue-stripe-elements-plus on internal single page app. As there is no need to keep the stripe code running after user leaves change credit card module I want to unload Stripe pletely but it doesn't appear to be that easy.
After I unload it in ponent's destroyed
hook and remove added iframes:
destroyed () {
this.$unloadScript('https://js.stripe./v3/');
//delete window.Stripe; // mented 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);
}));
},
iframes which were added by Stripe:
are reappearing again after a while (one of them):
Seems like this iframe is recreated by Stripe's listeners which were attached to window object on message event. I'm unable to remove this listener because the handler function is located in an iframe which is inside iframe, so the browser won't let me access its internals.
Moreover, this listener is making unwanted requests to stripe:
XHR finished loading: POST "https://m.stripe./4".
Share
Improve this question
edited Aug 10, 2022 at 14:04
Skatox
4,28412 gold badges45 silver badges49 bronze badges
asked Mar 12, 2019 at 10:16
van_folmertvan_folmert
4,53710 gold badges51 silver badges97 bronze badges
2 Answers
Reset to default 0You can use setTimeout(destroyed, 1000)
Instead of manually removing elements from DOM, you should use Stripe element's official destroy method. It should clear all Stripe listeners too.
With this lib, you can try something like this:
<template>
<div ref="card" />
</template>
<script>
let stripe = window.Stripe('pk_test_xxxxxxxxxxxx'),
elements = stripe.elements(),
card = undefined;
export default {
name: 'Payment',
mounted() {
card = elements.create('card');
card.mount(this.$refs.card);
},
beforeDestroy() {
card.destroy(this.$refs.card);
},
}
</script>
本文标签: javascriptHow to remove Stripe39s iframesStack Overflow
版权声明:本文标题:javascript - How to remove Stripe's iframes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745667263a2669359.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论