{"id":1530,"date":"2014-04-20T20:42:28","date_gmt":"2014-04-20T20:42:28","guid":{"rendered":"http:\/\/www.robertprice.co.uk\/robblog\/?p=1530"},"modified":"2016-01-22T13:36:23","modified_gmt":"2016-01-22T13:36:23","slug":"fixing-national-rail-mobile-website-iphones","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/","title":{"rendered":"Fixing The National Rail Mobile Website For iPhones"},"content":{"rendered":"<p>I&#8217;ve been frustrated that the National Rail Enquiries mobile website doesn&#8217;t work properly on my Apple iPhone 4s, running iOS7, so I decided to take a look and see what is actually going on.<\/p>\n<p>You can turn on debugging on your iPhone in the settings, so I turned this on, and loaded Safari on my Macbook Pro to take a look at what was actually happening.<\/p>\n<p>The &#8220;Go&#8221; button on the mobile website acts as a submit button so I put a breakpoint on it to see what happened.<\/p>\n<p>The event handler calls a function called setRecents, and it fails when it tries to save my recent stations to localStorage.<\/p>\n<pre class=\"lang:js decode:true \" >if (hasStorage) {\r\n    localStorage.setItem(\"recentStations\", recVal);\r\n} else {\r\n    setCookie(\"recentStations\", recVal, 365);\r\n}<\/pre>\n<p>The <code>hasStorage<\/code> global variable has a true value, allowing it to try to save to local storage, so I tried setting this to false and tried again. This time to website worked as it falls back to using cookies. So the problem is with localStorage on mobile Safari, I&#8217;m not sure why.<\/p>\n<p>I then took a look to see how hasStorage was set. It was being set in the following function.<\/p>\n<pre class=\"lang:js decode:true \" >function checkStorage() {\r\n    \/\/ Feature detect + local reference\r\n    var storage,\r\n    fail,\r\n    uid;\r\n    try {\r\n        uid = new Date;\r\n        (storage = window.localStorage).setItem(uid, uid);\r\n        fail = storage.getItem(uid) != uid;\r\n        storage.removeItem(uid);\r\n        fail &amp;&amp; (storage = false);\r\n    } catch (e) {}\r\n    if (storage) {\r\n        hasStorage = true; \/\/if localstorage available\r\n    }\r\n};\r\n<\/pre>\n<p>I set breakpoints through the function, reloaded and single stepped what was happening in the debugger.<\/p>\n<p>The <code>uid<\/code> was correctly set to a <code>Date<\/code> object with the current date and time. The next line was where the problem occured. <code>storage<\/code> was assigned as a <code>Storage<\/code> object, but the <code>setItem<\/code> method failed. This meant that the storage variable was set, but an exception was thrown. The exception handler does nothing, so the line after was executed. This sees that <code>storage<\/code> is available, but not that it didn&#8217;t work, so sets <code>hasStorage<\/code> incorrectly to true.<\/p>\n<p>The fix would be to modify the exception handler to set <code>storage<\/code> to false instead of doing nothing.<\/p>\n<p>If any developers of the National Rail website are reading this, please add this line so I can use your website to plan my train journeys again using my iPhone!<\/p>\n<p><a href=\"https:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png\" alt=\"The National Rail mobile website on an iPhone\" width=\"320\" height=\"480\" class=\"aligncenter size-full wp-image-1532\" \/><\/a><\/p>\n<p>All information correct at time of writing and publishing. 20th April 2014.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been frustrated that the National Rail Enquiries mobile website doesn&#8217;t work properly on my Apple iPhone 4s, running iOS7, so I decided to take a look and see what is actually going on. You can turn on debugging on your iPhone in the settings, so I turned this on, and loaded Safari on my &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fixing The National Rail Mobile Website For iPhones&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[24,27,31,61],"class_list":["post-1530","post","type-post","status-publish","format-standard","hentry","category-dev","tag-html5","tag-ios","tag-javascript","tag-safari"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Fixing The National Rail Mobile Website For iPhones - Robert Price<\/title>\n<meta name=\"description\" content=\"A run through of why the National Rail website doesn&#039;t work on iPhones.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fixing The National Rail Mobile Website For iPhones - Robert Price\" \/>\n<meta property=\"og:description\" content=\"A run through of why the National Rail website doesn&#039;t work on iPhones.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-20T20:42:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-01-22T13:36:23+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Fixing The National Rail Mobile Website For iPhones\",\"datePublished\":\"2014-04-20T20:42:28+00:00\",\"dateModified\":\"2016-01-22T13:36:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/\"},\"wordCount\":336,\"image\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/IMG_345911.png\",\"keywords\":[\"HTML5\",\"iOS\",\"JavaScript\",\"safari\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/\",\"name\":\"Fixing The National Rail Mobile Website For iPhones - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/IMG_345911.png\",\"datePublished\":\"2014-04-20T20:42:28+00:00\",\"dateModified\":\"2016-01-22T13:36:23+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"description\":\"A run through of why the National Rail website doesn't work on iPhones.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/IMG_345911.png\",\"contentUrl\":\"http:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/IMG_345911.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/fixing-national-rail-mobile-website-iphones\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fixing The National Rail Mobile Website For iPhones\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Fixing The National Rail Mobile Website For iPhones - Robert Price","description":"A run through of why the National Rail website doesn't work on iPhones.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/","og_locale":"en_GB","og_type":"article","og_title":"Fixing The National Rail Mobile Website For iPhones - Robert Price","og_description":"A run through of why the National Rail website doesn't work on iPhones.","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/","og_site_name":"Robert Price","article_published_time":"2014-04-20T20:42:28+00:00","article_modified_time":"2016-01-22T13:36:23+00:00","og_image":[{"url":"http:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png","type":"","width":"","height":""}],"author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Fixing The National Rail Mobile Website For iPhones","datePublished":"2014-04-20T20:42:28+00:00","dateModified":"2016-01-22T13:36:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/"},"wordCount":336,"image":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/#primaryimage"},"thumbnailUrl":"http:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png","keywords":["HTML5","iOS","JavaScript","safari"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/","name":"Fixing The National Rail Mobile Website For iPhones - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/#primaryimage"},"image":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/#primaryimage"},"thumbnailUrl":"http:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png","datePublished":"2014-04-20T20:42:28+00:00","dateModified":"2016-01-22T13:36:23+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"description":"A run through of why the National Rail website doesn't work on iPhones.","breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/#primaryimage","url":"http:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png","contentUrl":"http:\/\/www.robertprice.co.uk\/robblog\/wp-content\/uploads\/2014\/04\/IMG_345911.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/fixing-national-rail-mobile-website-iphones\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Fixing The National Rail Mobile Website For iPhones"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/1530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=1530"}],"version-history":[{"count":1,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/1530\/revisions"}],"predecessor-version":[{"id":1568,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/1530\/revisions\/1568"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=1530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=1530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=1530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}