0

When I use the standard technique ons-navigation, the javascript code on the ons-page does not execute. Does anyone know what I do wrong?

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-  scalable=no">
  <script src="components/loader.js"></script>
    <link rel="stylesheet" href="components/loader.css">
    <link rel="stylesheet" href="css/style.css">
  <script>
     ons.bootstrap();
     ons.disableAutoStatusBarFill();  // (Monaca enables StatusBar plugin by default)
  </script>
</head>
<body>
  <ons-navigator var="myNavigator" page="login.html">
  </ons-navigator> 
</body>
</html>

And here is the login.html:

<ons-page>

<script>
  console.log("test11");   
</script>

</ons-page>
Jasper
  • 101
  • 1
  • 12

1 Answers1

0

The reason why it's not working is that the browser won't execute script tags that are added through replacing el.innerHTML, which is what Onsen does when you push a page.

Please see this question for why it's not working: Can scripts be inserted with innerHTML?

You shouldn't use inline script tags mixed in your HTML. Please look up how to structure you're JavaScript.

Community
  • 1
  • 1
Andreas Argelius
  • 3,604
  • 1
  • 13
  • 22