user766090
user766090

Reputation:

Calling from android to a html file

In android i have used a WebView which is calling other HTML file(say one.html) which in turn calling other HTML file(say second.html).In second.html there is one javascript function.I want to call that function and pass some parameter too.These data i want to pass data from activity where WebView is present.How can i do that because it is calling one.html which in turn calling second.html? Any suggestion please.

one.html:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="w3.org/1999/xhtml">
<head>
  <title></… http-equiv="refresh" content="0;url= image.html" />
</head>
<body></body>
</html>

Upvotes: 0

Views: 487

Answers (1)

user180100
user180100

Reputation:

You could add the "datas" to the query string, like this one.html?foo=1&bar=2 and pass those data to second.html using the same way.

one.html:

<html>
<head>
<script type="application/javascript">
// borrowed from http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

location.href = "second.html?foo=" + getQuerystring('foo', '') +
  "&bar=" + getQuerystring('bar', '');
</script>
</head>
<body>
</body>
</html>

second.html:

<html>
<!-- whatever -->
</html>

But if one is a simple redirection (refresh with timing 0) you should load directly in your Webview second.html (and pass parameters by the query string)

Note: not tested

Upvotes: 1

Related Questions