0

I am trying to redirect the current html page on screen to another html file, both files share the same location.

I know there are a lot online about this info but it is not working for me, my app just crashed

The app loads the html file from the .java file in android by using this code:

WebView view = new WebView(this);
        view.getSettings().setJavaScriptEnabled(true);
        view.loadUrl("file:///android_asset/htmlfile.html");
        setContentView(view);

Here is what i have tried

<p class="btn animated fadeIn"><a href='android_asset/home.html' class="btn animated fadeIn">GO!</a></p>

I have also tried to use a form onclick

<form>
<input type="button" value="GO!" onclick="file:///android_asset/home.html" />
</form>

Help is appreciated

Turnip
  • 35,836
  • 15
  • 89
  • 111
user9446871
  • 37
  • 1
  • 5
  • 2
    "my app just crashed" — This suggests that the more context is needed (e.g. what is your "app"?) to understand the question. Your first code example should work fine. (Your second is nonsense, the `onclick` attribute value is expected to be the body of a JavaScript function, not a URL). – Quentin Mar 19 '18 at 11:07
  • if they are on the same folder, you can simply put `href="yourPage.html"` – Phiter Mar 19 '18 at 11:07
  • My first code does not seem to go to the html file, my app just stops working in android. My app currently is just a loading screen and it needs to load the next html file through this button – user9446871 Mar 19 '18 at 11:09
  • If this is some sort of hybrid app (Phonegap/Cordova) you need to make this clear in your question. – Turnip Mar 19 '18 at 11:11
  • This is just a simple android app made using java sdk, it literally only has a main html file as the startup, containing 1 button and is failing to direct to next html file – user9446871 Mar 19 '18 at 11:12
  • Android apps are built with Java not HTML/CSS/Javascript. Do you mean that you are loading your HTML into a WebView? – Turnip Mar 19 '18 at 11:15
  • yes, i use this code to load the html file `WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.loadUrl("file:///android_asset/htmlfile.html"); setContentView(view);` – user9446871 Mar 19 '18 at 11:17
  • All of this information should be in your question. See [MCVE] – Turnip Mar 19 '18 at 11:19

2 Answers2

0

Try this : (change myDomain value by url of your first page);

function goToInteralLink(path){
  var myDomain = 'http://example.com';
  window.location.href = myDomain + "/" + path;
}
<form>
<input type="button" value="GO!" onclick="goToInteralLink('android_asset/home.html')" />
</form>
Arash Hasanzade
  • 490
  • 3
  • 12
-1

As you are saying both files have the same location, So use this code below (You just need to remove 'android_asset/' from href attribute ):

<p class="btn animated fadeIn"><a href='home.html' class="btn animated fadeIn">GO!</a></p>
ninjazaman
  • 71
  • 2