Reactjs 重定向时关闭iframe
我在模态中有一个iframeReactjs 重定向时关闭iframe,reactjs,iframe,xmlhttprequest,fetch,Reactjs,Iframe,Xmlhttprequest,Fetch,我在模态中有一个iframe const ThreeDSecure = ({ paymentRequest, md, termUrl, issuerUrl, source, promotions, products, userProfile }) => { const dispatch = useDispatch(); const formId = `${source}-form`; window.ad
const ThreeDSecure = ({
paymentRequest,
md,
termUrl,
issuerUrl,
source,
promotions,
products,
userProfile
}) => {
const dispatch = useDispatch();
const formId = `${source}-form`;
window.addEventListener(
'message',
function(event) {
...
},
false
);
const submitForm = () => {
setTimeout(() => {
if (document.forms[formId]) {
document.forms[formId].submit();
}
}, 100);
};
return (
<ThreeDSecureModal
renderBodyContent={() => (
<iframe
height="500"
width="100%"
name="threeDSiFrame"
title="threeDSiFrame"
frameBorder="0"
onLoad={submitForm()}
>
<form
action={issuerUrl}
id={formId}
method="POST"
target="threeDSiFrame"
>
<input
type="hidden"
name="loadReq"
value={loadReq}
/>
</form>
</iframe>
)}
/>
);
在mysubmitForm()
中使用以下代码:
但它抛出了CORS错误:
Access to fetch at 'https://checkoutshopper-test.adyen.com/checkoutshopper/threeDS2.shtml' from origin 'https://checkout.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
有没有办法解决这个问题,因为银行不会把我们列入白名单
fetch(issuerUrl, {
method: 'POST',
body: new FormData(document.forms[formId]),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(res => res.text())
Access to fetch at 'https://checkoutshopper-test.adyen.com/checkoutshopper/threeDS2.shtml' from origin 'https://checkout.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.