0

I'm trying to create a basic Web View application, with demo.html and demo.js files. App opened without errors but showing a blank page!

demo.html:

<!DOCTYPE HTML>    
<html>
    <head>
    <script src="demo.js" type="text/javascript" />
    </head>
    <body>

    <form name="form1" onSubmit="return showInfo()" autocomplete="on">
      First name:<input type="text" id="fname"><br>
      Last name: <input type="text" id="lname"><br>
      <input type="submit">
    </form>

    </body>
    </html>

demo.js:

function showInfo()
{
    var str1= document.getElementById('fname').value;
    var str2= document.getElementById('lname').value;
    var res = str1.concat(' '+str2);
    alert('Hi,' +res);
}

Here I loaded URL:

 WebView webView = (WebView)findViewById(R.id.WebView1);
 webView.getSettings().setJavaScriptEnabled(true);
 webView.loadUrl("file:///android_asset/Web/demo.html");

When I tried to open the same demo.html on my PC , its not opened. Then I removed <script src="demo.js" type="text/javascript" /> then It opened the page. Is this means Java script is not supported ?

I checked my PC JavaScript status with https://www.whatismybrowser.com/is-javascript-enabled It says JavaScript is enabed in my browser, Wonder why its not working in my PC and android emulator !?

Thanks

7
  • whats in the javascript file Commented Jul 19, 2015 at 10:01
  • @RachelGallen updated question with js file Commented Jul 19, 2015 at 10:48
  • your file path must be incorrect. it works fine if you just put the script in script tags in the html document Commented Jul 19, 2015 at 10:51
  • demo.html and demo.js in same directory. demo.html is not opening in my PC too. without calling js in html file it is opening. may be issue with javascript in my browser ! Commented Jul 19, 2015 at 10:54
  • 1
    works fine for me - what browser are you using? Did you try just putting it in script tags in the head like i suggested Commented Jul 19, 2015 at 10:55

1 Answer 1

2

You are missing a tag at the end of your script call.

Your html should look like this

<html>
<head>
<script src="demo.js" type="text/javascript" /></script>

</head>
<body>

<form name="form1" onSubmit="return showInfo()" autocomplete="on">
  First name:<input type="text" id="fname"><br>
  Last name: <input type="text" id="lname"><br>
  <input type="submit">
</form>

</body>
</html>

Then it will work

Sign up to request clarification or add additional context in comments.

Comments

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.