I'm using Cordova/PhoneGap and Onsen UI. I have two html pages. Switch(pushpage) button is working perfect. But Javascript not working in search.html
Here is my code:
index.html
...
<body>
<ons-navigator title="Navigator" var="myNavigator">
<ons-button
onclick="myNavigator.pushPage('search.html', { animation: 'lift' })">
Switch Page
</ons-button>
</ons-navigator>
</body>
search.html
<ons-page>
<script>
alert('Testing Javascript');
</script>
</ons-page>
The search.html page is inserted dynamically when myNavigator.pushPage('search.html') is called.
When a <script> tag is inserted in this way the code is not executed.
Please refer to this question for more info: Can scripts be inserted with innerHTML?
In order to execute some script when a page is pushed you can use the postpush event:
ons.ready(function() {
myNavigator.on('postpush', function() {
alert('Hello, world!');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With