1

I'm creating an android webview that loads a simple html page:

WebView myWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowContentAccess(true);
    myWebView.loadUrl("http://10.0.2.2/external/login.html");

But for some reason, when the page loads it is loading http://10.0.2.2/external/index.html all the time, even if I explicitly specify a different html page such as login.html above. I'm running a simple http server at http://10.0.2.2/ (my local machine). Is there a setting somewhere that causes this? How can I make it load the page I want it to and not index.html?

Thanks.

5
  • posts the code of your login.html page. Commented Dec 15, 2015 at 21:42
  • It could be annything - TEST <br> TEST - happens no matter what Commented Dec 15, 2015 at 21:51
  • Actually it doesn't happen without this - webSettings.setJavaScriptEnabled(true); But it needs javascript - any way around that? Commented Dec 15, 2015 at 21:51
  • ok check my answer and show us the code of the login.html page. Commented Dec 15, 2015 at 21:53
  • See below. Redirect problem in javascript - not a problem with android or android studio etc. Commented Dec 16, 2015 at 22:34

1 Answer 1

0

Actually it doesn't happen without this - webSettings.setJavaScriptEnabled(true);

Probably your web pages contain a script to redirect to index.html, like :

window.location = " http://10.0.2.2/external/index.html ";
Sign up to request clarification or add additional context in comments.

1 Comment

This ended up being a redirect problem with the javascript that I thought was inherently tied to android studio or android but was incorrect. It wasn't exactly as simple as the location=? but it wasn't really auto-selecting the index.html as I thought it was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.