SHARE
TWEET

Untitled

a guest Apr 24th, 2019 159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title>It works!</title>
  6.   <script>
  7.     var handleClick = function() {
  8.       var ownBody = document.getElementsByTagName('body')[0]
  9.       var iframe = document.createElement('iframe');
  10.       iframe.setAttribute('style', 'display: none');
  11.       iframe.addEventListener('load', function(e) {
  12.         var response = e.target.contentWindow.document.getElementsByTagName('body')[0].innerText;
  13.  
  14.         console.log('got response', response)
  15.  
  16.         document.getElementById('output').innerText = response;
  17.  
  18.         ownBody.removeChild(iframe)
  19.       })
  20.       iframe.src = 'someApi?user=A&amp;score=1'
  21.  
  22.       console.log('before request')
  23.  
  24.       ownBody.appendChild(iframe);
  25.  
  26.       console.log('after request')
  27.     };
  28.  
  29.     document.addEventListener('DOMContentLoaded', function() {
  30.       document.getElementById('send').addEventListener('click', handleClick);
  31.     })
  32.   </script>
  33. </head>
  34. <body>
  35.   <pre id="output"></pre>
  36.  
  37.   <input id="send" type="button" name="submit" value="Get it!" />
  38. </body>
  39. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top