2

I'm trying to load the following URL into a webview: index.html?name

This works fine on Android 2.2 device and emulator, as well as Android 3.1 emulator. However, when I load the app up on my Android 3.1 galaxy tab, I am met with an error:

Webpage not available

The webpage at file:///android_asset/index.html?name might be temporarily down or it may have moved permanently to a new web address.

Seems like it's not registering that it's a local asset and is trying to access the web for it. Any idea why this is happening, and only on the physical 3.1 device? If I try to load just index.html then it works fine on everything. I doubt it, but could it have something to do with the question mark?

Thanks in advance.

Community
  • 1
  • 1
user979551
  • 23
  • 2
  • 4

3 Answers3

1

I had the same issue but there's a workaround...

Change ?name to #name instead and it will work, since named anchors are supported by Android. You can then use JavaScript like the following to detect the anchor and act upon it:

if (window.location.href.search('#name') > 0) 
{
  // Do something
}
Robin Nixon
  • 751
  • 5
  • 2
0

I think you've answered your own question. Over HTTP, the '?' in a URL is used to separate URL parameters from the main URL; although it's interesting that this works with file:///android_asset in the emulators, I'd hesitate to call it a bug.

If you need to pass arguments to the HTML page (perhaps for javascript to use), one option would be to use anchor syntax (e.g. file:///android_asset/index.html#name)

Phil Lello
  • 8,377
  • 2
  • 25
  • 34
0

As per the standard, file:// URLs don't support query strings, like your ?name. So this is hardly a bug. What are you trying to accomplish in the first place? Which part of your code is supposed to process the name? If JavaScript, then load the page, then invoke some JavaScript on it via another loadUrl() call with a javascript: URL.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • I have some javascript that runs and I need to pass in some data for that, problem is the javascript has to load immediately so I can't retrieve data after the page has already been fetched. Thanks for your insight though! – user979551 Oct 24 '11 at 20:14