加载任何网站后运行自定义JavaScript code [英] Run custom javascript code after loading any website
问题描述
我正在服用关于Web浏览器的性能读数,所以需要访问浏览器的 window.performance
对象。
为了收集这些数据我写了一个JavaScript文件,我需要添加到我需要测试如页面的DOM collect.js。 www.google.com,www.facebook.com等等...
I am working on taking readings about web browser performance and so need to access the window.performance
object of the browser.
To collect this data i have written a javascript file, collect.js which i need to add to the DOM of the page that i need to test eg. www.google.com, www.facebook.com and so on...
此外,我需要运行这个测试约1000网站,任何手动的方法是不可能的。我需要它以某种方式自动执行。
Also i need to run this test for about 1000 websites, any manual approach is out of the question. I need it to be automated somehow.
我怎么会去这样做?
编辑:我需要运行在Android浏览器这些测试,所以我需要的移动导向的解决方案
I need to run these tests on an android browser, so i need mobile oriented solutions.
推荐答案
您可以创建一个的WebView
组件简单的Android应用程序。这样,您就可以控制哪些网址
s的加载,并插入JS code。
You can create a simple android app with a WebView
component. This way you can control which URL
s are loaded and also insert your JS code.
http://developer.android.com/guide/tutorials/意见/ HELLO-webview.html
修改结果
你可以运行任何JavaScript是这样的:
EDIT
You can run any javascript like this:
实现自定义的WebView
:
public class WebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// Execute your javascript below
view.loadUrl("javascript:...");
}
}
这篇关于加载任何网站后运行自定义JavaScript code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!