0

I am working on building some pages in polymer to use in android web view.

demo code below

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8 />
        <title></title>
    </head>

    <body>
        <!-- Bootstrap Core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link rel="import" href="bower_components/polymer/polymer.html">

        <dom-module id="trail-app">
            <template>
                <style>
                </style>

                <div id="content"></div>

            </template>

            <script>
                 Polymer({
                 is: "trail-app",

                 loadDataOne:function(data){
                    document.getElementById("content").innerHTML = data;
                 },

                 });
            </script>

            <script type="text/javascript">

                function loadDataTwo(data) {
                    document.getElementById("content").innerHTML = data;
                }

            </script>   
        </dom-module>
        <trail-app></trail-app>
 </body>
</html>

So my problem here is if the function loadDataTwo is called like this myWebView.loadUrl("javascript:loadDataTwo('Hello World!')"); it is working fine. But if the function loadDataOne is called same way its not working.How to resolve.

aries12
  • 370
  • 2
  • 18
  • That is because `loadOne` is a function defined inside `trial-app`. In order to call loadOne you need to select `trial-app` and then call `loadOne` on it. – a1626 Mar 19 '17 at 08:44
  • if I do `var temp = document.querySelector('trail-app'); temp.loadDataOne()` it works.Should I select trail-app in android webview? – aries12 Mar 20 '17 at 04:54
  • Yes, because `loadOne` is a function of `trail-app` element – a1626 Mar 20 '17 at 06:38
  • i have posted solution below.Thank you @a1626 for the comment. – aries12 Mar 20 '17 at 09:33

1 Answers1

0

I tried myWebView.loadUrl("javascript:var temp = document.querySelector('trail-app');temp.loadDataOne('Hello World!')"); it worked fine.

aries12
  • 370
  • 2
  • 18