Quike start
step1
npm i paymonade-iframe
step2
import { initPayIframe } from 'paymonade-iframe';
initPayIframe({
containerId: 'iframeId',
iframeUrl: 'your trade url'
});
<div>
<div id="iframeId" style="height: 900px; width: 100%"></div>
</div>
Attributes
The following Attributes can be passed to iframe on the parent page.
maxHeight / maxWidth
default: infinity
type: integer
Set maximum height/width of iFrame.
minHeight / minWidth
default: 0
type: integer
Set minimum height/width of iFrame.
sizeHeight
default: true
type: boolean
Resize iFrame to content height.
sizeWidth
default: false
type: boolean
Resize iFrame to content width.
warningTimeout
default: 5000
type: integer
Set the number of milliseconds after which a warning is logged if the iFrame has not responded. Set to 0 to supress warning messages of this type.
Events
The following callback events can be passed to iframe on the parent page.
onClose
onClose: (iframeID) => boolean;
Called before iFrame is closed via parentIFrame.close() or iframe.iFrameResizer.close() methods. Returning false will prevent the iFrame from closing.
onClosed
onClosed: (iframeID) => undefined;
Called after iFrame is closed via parentIFrame.close() or iframe.iFrameResizer.close() methods.
onInit
onInit: (iframe) => undefined;
Called after initial setup.
onMessage
initPayIframe({
onMessage: function (messageData) {
// Callback fn when message is received
alert(messageData.message)
},
onClosed: function (id) {
// Callback fn when iFrame is closed
},
})
Synchronized updates of URLs
To synchronize URL updates, two issues need to be addressed: one is when to trigger the update action, and the other is the law of URL updates, which is the maintenance of the mapping relationship between the URL address of the parent page (system A) and the URL address of the iframe (system B).
To ensure the normal synchronization and update function of the URL, there are three situations that need to be met:
Case 1: Page refresh, iframe can load the correct page;
Case 2: Page redirection, browser address bar can be updated correctly;
Case 3: Clicking on the browser's forward or backward button will synchronize the changes in the address bar and iframe;
Receive message posted from iFrame with the parentIFrame.sendMessage() method.
onResized
onResized: ({ iframe, height, width, type }) => undefined;
Function called after iFrame resized. Passes messageData object containing the iFrame, height, width and the type of event that triggered the iFrame to resize.
IFrame Object Methods
Once the iFrame has been initialized, an iFrameResizer object is bound to it. This has the following methods available.
close()
Remove the iFrame from the page.
moveToAnchor(anchor)
Move to anchor in iFrame.
resize()
Tell the iFrame to resize itself.
sendMessage(message, [targetOrigin])
Send data to the containing page, message can be any data type that can be serialized into JSON. The targetOrigin option is used to restrict where the message is sent to, in case your iFrame navigates away to another domain.
initPayIframe({
sendMessage: function (messageData) {
// Callback fn when message is received
alert(messageData.message)
},
onClosed: function (id) {
// Callback fn when iFrame is closed
},
})