Using this gist to prevent links from launching a browser when the site is saved as a home screen web app.
The script is working, to an extent. The problem is that for some reason it is calling the target page twice. This is causing Jquery Mobile to display error loading page on every page load, despite successfully loading the page.
Here is an example link:
<a href="/bookings/3/features" data-ajax="false">Link Example</a>
Here is the log from the server:
Started GET "/bookings/3/features" for 10.104.4.210 at 2012-03-02 17:13:25 +0000
Processing by FeaturesController#index as HTML
Parameters: {"booking_id"=>"3"}
Booking Load (0.3ms) SELECT `bookings`.* FROM `bookings` WHERE `bookings`.`id` = 3 LIMIT 1
Car Load (0.2ms) SELECT `cars`.* FROM `cars` WHERE `cars`.`id` = 2 LIMIT 1
CarModel Load (0.2ms) SELECT `car_models`.* FROM `car_models` WHERE `car_models`.`id` = 1 LIMIT 1
Manufacturer Load (0.2ms) SELECT `manufacturers`.* FROM `manufacturers` WHERE `manufacturers`.`id` = 1 LIMIT 1
Feature Load (0.3ms) SELECT `features`.* FROM `features` WHERE `features`.`car_model_id` = 1
(0.2ms) SELECT COUNT(*) FROM `car_colours` WHERE `car_colours`.`car_model_id` = 1
Rendered features/index.html.erb within layouts/frontEnd (5.2ms)
Rendered shared/_footer.html.erb (1.1ms)
Completed 200 OK in 62ms (Views: 56.8ms | ActiveRecord: 1.4ms)
Started GET "/bookings/3/features" for 10.104.4.210 at 2012-03-02 17:13:25 +0000
Processing by FeaturesController#index as HTML
Parameters: {"booking_id"=>"3"}
Booking Load (0.4ms) SELECT `bookings`.* FROM `bookings` WHERE `bookings`.`id` = 3 LIMIT 1
Car Load (0.2ms) SELECT `cars`.* FROM `cars` WHERE `cars`.`id` = 2 LIMIT 1
CarModel Load (0.2ms) SELECT `car_models`.* FROM `car_models` WHERE `car_models`.`id` = 1 LIMIT 1
Manufacturer Load (0.2ms) SELECT `manufacturers`.* FROM `manufacturers` WHERE `manufacturers`.`id` = 1 LIMIT 1
Feature Load (0.3ms) SELECT `features`.* FROM `features` WHERE `features`.`car_model_id` = 1
(0.2ms) SELECT COUNT(*) FROM `car_colours` WHERE `car_colours`.`car_model_id` = 1
Rendered features/index.html.erb within layouts/frontEnd (4.5ms)
Rendered shared/_footer.html.erb (1.1ms)
Completed 200 OK in 26ms (Views: 20.8ms | ActiveRecord: 1.3ms)
The problem is that jQuery Mobile tries to optimize page loading and minimize requests by doing ajax instead of regular page loads. This causes the first request to be made by jQuery mobile and whilst jQuery is awaiting a return the “stay_standalone” script triggers and loads the page in a regular http page load.
You can see the jQuery Mobile code related to this function in this two links: first in the init, and then checking for ajax flag and finally making a request. This is also in jQuery Mobile’s global config docs.
I searched a little about jQuery Mobile in standalone mode and didn’t find anything specific. There is 2 solutions to this problem tough:
If this does not work as expected, you can disable the
ajaxEnabledfeature in jQuery Mobile like described on their docs:$(document).bind(“mobileinit”, function(){
ajaxEnabled: false
});
The second option is not optimal but may be a good solution until you figure how jQuery Mobile could prevent the pages loading in Mobile Safari.