Last active
August 29, 2015 14:07
-
-
Save bjrmatos/d192e455ca91803d4783 to your computer and use it in GitHub Desktop.
redirects for phantomjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renderPage(url) { | |
var page = require('webpage').create(); | |
var redirectURL = null; | |
page.onResourceReceived = function(resource) { | |
if (url == resource.url && resource.redirectURL) { | |
redirectURL = resource.redirectURL; | |
} | |
}; | |
page.open(url, function(status) { | |
if (redirectURL) { | |
renderPage(redirectURL); | |
} else if (status == 'success') { | |
// ... | |
} else { | |
// ... | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment