Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JS in Framework7?

I create an application with framework7. Now I try to execute a javascript in my page-content, but it doesn't execute.

<div class="pages">
<div class="page  close-panel" data-page="item">
    <div class="page-content">
        <div class="content-block-title">Title</div>
        <script type="text/javascript">
          alert("testoutput"); // no alert
          console.log("TEST"); // no log
        </script>
    </div>
</div>

How can I run this javascript code ?

UPDATE

The page is loaded from an other HTML-Page.

like image 444
michael-mammut Avatar asked Jan 06 '23 03:01

michael-mammut


2 Answers

Use Callbacks (onPageInit) to execute code

like image 119
koolguy Avatar answered Jan 08 '23 18:01

koolguy


I had never heard of Framework7 before this, but after taking a look at the docs, I don't believe you are going to be able to use Javascript this way.

It would appear that for JS events, you have to scope the event inside a Framework7 constructor:

var myApp = new Framework7();

var $$ = Dom7;

$$('.alert-text').on('click', function () {
    myApp.alert('Here goes alert text');
});

Of course the above example is taken directly from the F7 documentation, and is dependent on a click event, but you may be able to try out the alert event as a method of myApp and see if that works for you.

like image 23
Jonathan Kempf Avatar answered Jan 08 '23 16:01

Jonathan Kempf