As a note, it works when deployed to a test device, just not in the emulators.
I also need to call the following code in c#, but dont know how to do it in Appery;
NavigationService.RemoveBackEntry();
The javascript is currently on the Load event. If I change this to be on the 'Tap' event, and then tap the screen to run the javascript, it works fine.
EDIT: I have now changed it from Load to Page Show and it works as expected.
It works fine in the browser on PC. It is the Appery preview (iOS) app that displays the strange behaviour.
This doesn't work with the appery portal app (iOS). I have explained below.