4

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 files can't be loaded from remote web page...

kelloti
  • 8,705
  • 5
  • 46
  • 82
Olegas
  • 10,349
  • 8
  • 51
  • 72

3 Answers3

4

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"

Olegas
  • 10,349
  • 8
  • 51
  • 72
1

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?

Krzysztof Wolny
  • 10,576
  • 4
  • 34
  • 46
  • Ok, i'll try to make my probles more clear... I have a remote page. This page has JS code. Some code are mine, and i want to hold this code on Android side. Some code is not mine, it is some service which is loading data from network (images, additional js code). I want to reduce bandwidth useage by putting mine code to Android side and not to download it by the network. As i have remote code, which intercats with remote servers, i can't use webView.loadData() method and can't use file:///android_asset/ As a workaround i want to "transfer" my sources via LoadUrl("javascript:...") call. – Olegas Mar 02 '11 at 06:15
-1

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

Rohit Mandiwal
  • 10,258
  • 5
  • 70
  • 83
  • I think you are wrong in GET request limit amount. As far as i know the GET request is limited to 2048 bytes. And where is no problems for now, i transferred about 2100 bytes throught loadUrl... But this is not meaning what there is no limit. – Olegas Feb 20 '11 at 16:23