jaunesarmiento / fries

Fries helps you prototype Android apps using HTML, CSS, and JavaScript.
MIT License
1.55k stars 222 forks source link

js is not call after transition ! #44

Closed florindumitru closed 11 years ago

florindumitru commented 11 years ago

When I navigate to another page the javascript from the destination page is not call/execute.

jaunesarmiento commented 11 years ago

Hi @florindumitru, yes Fries does not execute any scripts from the loaded page. You must add your scripts to index.html and listen for events there.

florindumitru commented 11 years ago

@jaunesarmiento pls also need to know if fries work on iOS and android 2.2 ?

jaunesarmiento commented 11 years ago

Here's a little something on how to do this, you must catch the push event that stack.js fires whenever a page gets pushed onto the screen.

So given that you have an inner page like this:

<div id="page2" class="page">
  <!-- some content here -->
</div>

You just need to do the following in your index.html:

<script type="text/javascript">
window.addEventListener('push', function () {
  if (document.getElementById('page2')) {
    console.log('We are on page 2');
    // do what you want here
  }
});
</script>

This may not be the best solution but I think this will work for now. @aymanfarhat and I have already had a few discussions on how to hook code when loading a new page. I think this is something that should really be included in Fries.

And no, I actually haven't tested Fries on iOS. And I believe it won't work on Android 2.2 due to its stock browser being outdated.