<p id="data"></p>
<p id="result">
</p>
<!--update the src of this iframe to the HTPURL you obtained from the https://test-htp.tokenex.com/api/v1 call -->
<iframe id="tokenExIframe" width="30%" height="20%" scrolling="no" frameborder="0" src="https://test-htp.tokenex.com/Interplx/Iframe/a84bf9c784774a62a4bce6e8e74d4823"></iframe>
<br/>
<button type="button" id="bthTokenize">Tokenize</button>
<button type="button" id="bthValidate">Validate</button>
<button type="button" id="btnReset">Reset</button>
<button type="button" id="btnPretty">Enable Pretty</button>
<button type="button" id="btnFocus">focus</button>
JavaScript
document.getElementById('bthValidate').onclick = validate;
document.getElementById('bthTokenize').onclick = tokenize;
document.getElementById('btnReset').onclick = reset;
document.getElementById('btnPretty').onclick = pretty;
document.getElementById('btnFocus').onclick = focus;
var iframe = document.getElementById("tokenExIframe");
//add event listener for postmessage
if (window.addEventListener) {
addEventListener("message", listener, false)
} else {
attachEvent("onmessage", listener)
}
//send the tokenize command to the iframe
function pretty() {
iframe.contentWindow.postMessage('enablePrettyFormat', 'https://test-htp.tokenex.com');
}
function focus() {
iframe.contentWindow.postMessage('focus', 'https://test-htp.tokenex.com');
}
//enable pretty formated pan
function tokenize() {
iframe.contentWindow.postMessage('tokenize', 'https://test-htp.tokenex.com');
}
//send the validate command to the iframe
function validate() {
iframe.contentWindow.postMessage('validate', 'https://test-htp.tokenex.com');
}
//send the reset command to the iframe
function reset() {
var iframe = document.getElementById("tokenExIframe");
iframe.contentWindow.postMessage('reset', 'https://test-htp.tokenex.com');
}
//handle the message from the iframe
function listener(event) {
if (event.origin === 'https://test-htp.tokenex.com') {
var message = JSON.parse(event.data);
switch (message.event) {
case 'focus':
if (message.data.value) {
//field has focus
} else {
//field does not have focus(blur)
}
case 'change':
// field changed
break;
case 'validation':
if (!message.data.isValid) {
//field failed validation
} else {
//validation valid!
}
break;
case 'post':
if (!message.data.success) {
// use message.data.error
} else {
document.getElementById('result').innerHTML = message.data.token;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.