开发者

Is there any limitation on Url's length in Android's WebView.loadUrl method?

开发者 https://www.devze.com 2023-02-11 06:02 出处:网络
I want to \"transfer\" local resources to a page, loaded from remote server. I want to do somthing like this:

I want to "transfer" local resources to a page, loaded from remote server.

I want to do somthing like this:

webView.loadUrl('http://my.server.com/page.html');
webView.loadUrl('javascript:function someLong(){}function codeHere(){}....');

This is for saving a bandwidth and reduce loading time.

As i see, assets fil开发者_开发知识库es can't be loaded from remote web page...


Looks like there is no limit or it is very large. I've done some tests with simple code

webView.loadUrl(
    "javascript:function a(s){alert(s.length + ' ' + s.substring(s.length-5))}");
String repeated = 
    String.format(String.format("%%0%dd", 80000), 0).replace("0", ".") + "xx";
webView.loadUrl("javascript:a('"+repeated+"')");

First line: define a function, second line - prepare long string, third one - call defined function with very long string argument.

It works perfectly. As a result i seeing JS alert saying: "80002 ...xx"


As you can read here webView.loadUrl("javascript:wave()"); only calls a JS methods, not inject them to HTML page. Maybe you want to use webView.loadData() or webView.loadDataWithBaseURL() methods? Or have I misunderstood you?


By default the loadURL makes a get request which is having a limit of 254 characters. That why the problem is.

0

精彩评论

暂无评论...
验证码 换一张
取 消