Skip to content

Instantly share code, notes, and snippets.

@firedfox
Created March 3, 2012 16:17
Show Gist options
  • Save firedfox/1966848 to your computer and use it in GitHub Desktop.
Save firedfox/1966848 to your computer and use it in GitHub Desktop.
test "phantomjs --web-security=no"
var page = require('webpage').create();
page.settings.loadImages = false;
page.onConsoleMessage = function(msg) { console.log(msg); };
var count = 0;
page.onLoadFinished = function() {
(0 == count++) && page.evaluate(function() {
// cross-domain iframe access
var i = document.createElement('iframe');
i.src = 'http://www.phantomjs.org/';
i.onload = function() {
console.log('get document in cross-domain iframe: ' + this.contentWindow.document);
};
document.body.appendChild(i);
// cross-domain XMLHttpRequest
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log('get text by cross-domain XMLHttpRequest: ' + xhr.responseText.substring(0, 15));
}
};
xhr.open('get', 'http://www.phantomjs.org/', true);
xhr.send();
});
};
page.open('http://www.google.com/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment