JavaScript Snippet – Query For Accessible IFRAMEs

IFRAMEs with SRC attribute such as about:blank or javascript:true are called orgin-free IFRAMEs,
IFRAMEs whom which loads a page, which enables the CORS headers, are called origin-permissive.

Both kinds allow accessing the internal document element from another domain (such as the main-page),
If you ever wonder how to get a list of those documents from your-own page, the easy answer is you have to try and it out figure-out later.

This snippet tries (silently) to access the document of every IFRAME it finds under the input-window object,
and returns a list of those where it manage to do so, successfully.

function get_document(win){
  var doc = null;
  try{
    doc = win.document || win.contentDocument || win.contentWindow.document; /* try access reference of document */
  }catch(err){}
  return doc;
}

function get_accessible_iframes(win){
  win = "undefined" === typeof win ? self : win; /* normalize input */

  return win.document.querySelectorAll("iframe").filter(function(iframe){
                                                          return null !== get_document(iframe);
                                                       });
}

/*
get_accessible_iframes();     // same as `get_accessible_iframes(self);`
get_accessible_iframes(top);
*/

also available in this here: https://gist.github.com/eladkarako/2e2450fe6b2b01b3263f342519f5cd87

HTTP Non-Standard Methods

CONNECT
COPY
DELETE
GET
HEAD
LOCK
MKCOL
MOVE
OPTIONS
PATCH
PING
POST
PROPFIND
PROPPATCH
PUT
TRACE
UNLOCK
X-PINGOTHER

You might find it especially useful for CORS directive ,
Here is an example on how to use it for Access-Control-Allow-Methods (PHP):

<?php
header('Access-Control-Allow-Methods: CONNECT,COPY,DELETE,GET,HEAD,LOCK,MKCOL,MOVE,OPTIONS,PATCH,PING,POST,PROPFIND,PROPPATCH,PUT,TRACE,UNLOCK,X-PINGOTHER');
?>

4Chan API – Cross-Domain Image Fetcher – Usage + Examples

The following example on my GitHub project-page, shows, hopefully a clear way, on how to do some Ajax requests on client side, fetching each of the threads in a board, in which all the posts, and all the image links within, 4chan_api

after fetching the information, a Handlebars-Mustache logicless template is using the aggregated data (images) to build a simple gallery,
which uses jQuery’s lazy-loading, so only images within the close-range of the browser’s VIEWPORT will be fetched from 4Chan (saving their’s data plan).

this is mainly academic, since the 4Chan-API documentation is quite poorly explained..