Preload iframe to increase loading speed
Overview
Use case
1
2
Add the card element container
<form type="post" id="payment-form">
<div class="form-group">
<label for="name" class="label control-label">Name</label>
<input type="text" id="name" class="field form-control">
</div>
<div id="card-element">
<!-- A TCO IFRAME will be inserted here. -->
</div>
<button class="btn btn-primary" type="submit">Generate token</button>
</form>4
Preload the iframe on page load
window.component = null;
window.addEventListener('load', function() {
// Initialize the JS Payments SDK client.
let jsPaymentClient = new TwoPayClient('YOUR_MERCHANT_CODE');
// Create the component that will hold the card fields.
let component = jsPaymentClient.components.create('card');
// Preload the card fields component in the desired HTML tag. This is where the iframe will be located.
component.preload('#card-element');
});Demo
<form method="post" id="payment-form">
<a href="javascript:show()">Show Iframe</a>
<a href="javascript:hide()">Hide Iframe</a>
<div id="card-element">
<!-- A TCO IFRAME will be inserted here. -->
</div>
</form>Last updated
Was this helpful?