title: check http header to see if url can be loaded in iframe
body: <p>I need to detect if a url can be loaded into iframe, and if not the url needs to be opened in next tab.</p>
  
  <p>I tried to download the header for given url and check <code>X-Frame-Options</code> header value.</p>
  
  <p>Here's what I tried:</p>
  
  <pre><code>$(document).on('opening', '.link-modal', function(e) {
      var target = $(e.target);
      var url = target.attr('data-izimodal-iframeURL');
  
      console.log(isIframeDisabled(url));
  });
  
  function isIframeDisabled($src) {
      try {
          $headers = get_headers($src, 1);
          // return $headers;
          $headers = array_change_key_case($headers, CASE_LOWER);
          // Check Content-Security-Policy
          if(isset($headers[strtolower('Content-Security-Policy')])){
              return true;
          }
          // Check X-Frame-Options
          if(isset($headers[strtolower('X-Frame-Options')] &amp;&amp;
              (strtoupper($headers['X-Frame-Options']) == 'DENY' ||
                  strtoupper($headers['X-Frame-Options']) == 'SAMEORIGIN')
              ))
          {
              return true;
          }
      } catch ( e ) {
          // Ignore error
      }
      return false;
  }
  </code></pre>
  
  <p>This function always gives <code>false</code> even though some urls are loading into iframe.</p>
  
  <p>It seems that code inside <code>try-catch</code> is not being run.</p>