操纵web视图获取URL就开始装货前 [英] Manipulate the url a webview gets before it starts loading
问题描述
我想补充当前位置的请求变量,URL的加载web视图这样我就可以使用这些信息在页面上没有重载或额外的请求。
I would like to add the current location as a request variable to URL's loaded in the webview so I can use this information on the page without reloads or extra requests.
我有shouldOverrideUrlLoading一个WebviewClient但这不接受请求时,他们使用的是使用loadURL通过。我看有可能拦截使用shouldInterceptRequest请求的URL,但我对API级别8和真的不希望改变这种只为这一点。
I have a WebviewClient with shouldOverrideUrlLoading but this doesn't receive requests when they are passed using loadUrl. I read it's possible to intercept the requested URL using shouldInterceptRequest but I'm on API level 8 and don't really want to change this only for this.
有没有一种方法来操纵URL,然后它被通过的WebView装?
Is there a way to manipulate the URL before it gets loaded by the webview?
推荐答案
是的,改变网址
要求,然后使用loadURL
。您可以创建一个函数,它会修改网址
,并调用它的使用loadURL
和 shouldOverrideUrlLoading
Yes, change the Url
before you call for loadUrl
. You can create one function which modifies the Url
and call it for loadUrl
and in shouldOverrideUrlLoading
public Url addLocationToUrl(Url url) {
Url newUrl = url;
//do something with url
return newUrl;
}
loadUrl(addLocationToUrl(someUrl));
//and in your WebViewClient
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
mWebView.loadUrl(addLocationToUrl(someUrl));
return true;
}
这篇关于操纵web视图获取URL就开始装货前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!