Iframve v2 - iOS Touch

by TokenEx Support

HTML

<p id="data"></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/iframe/v2/a79cbd83ccf64d7e82a0c008c5f22b13"></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)
  //add a focus event to the parent window so when the parent comes back in focus, the iframe validation will fire.
  addEventListener("focus", validate, false)
} else {
  attachEvent("onmessage", listener)lidateva
  //add a focus event to the parent window so when the parent comes back in focus, the iframe validation will fire.
  attachEvent("onfocus", validate)
}

//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...