Retrieving source code of site in InAppBrowser

孤人 提交于 2020-05-28 04:03:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!