问题
When opening a website in the InAppBrowser, is there a way to retrieve the source code of the website?
This is needed for a PhoneGap app for iOs.
I was thinking either by a javascript injection that could read and return the source, or by writing it in objective c and make a plugin - if either of these options would be possible.
回答1:
I think you can do that by injecting js script after page load event is fired in InAppBrowser.
var code = 'javascript:alert("xxxxxxx")';
var ref = window.open('YOUR PAGE', '_blank', 'location=yes');
ref.addEventListener('loadstop', function(event) {
//wait 1 second till page load
setTimeout(function(){
ref.executeScript({
code: code,
}, function() {
console.log('script was injected successfully');
});
}, 1000);
});
replace variable 'code' value with your code to scrap the whole page, I mean something like this:
var markup = document.documentElement.innerHTML;
then send the variable 'markup' value to your server
来源:https://stackoverflow.com/questions/20937196/retrieving-source-code-of-site-in-inappbrowser