11

"googlechrome://www.lego.com" opened in mobile Safari will switch to Google Chrome iOS app to open the URL. This allows for scriptlets like the one below, which allows you to open the current page in Google Chrome iOS app, switching from mobile Safari:

(function()%7Bif(document.location.href.indexOf('http')===0)document.location.href=document.location.href.replace(/%5Ehttp/,'googlechrome');%7D)();

My question is, can the reverse be done? I tried "safari://www.lego.com", and it is simply an invalid URL. Can you make a scriptlet which switches from Google Chrome to mobile Safari to open the current page.

woz
  • 10,888
  • 3
  • 34
  • 64
jonS90
  • 1,369
  • 2
  • 11
  • 15
  • Have you seen this: http://stackoverflow.com/questions/7930001/force-link-to-open-in-mobile-safari-from-a-web-app-with-javascript? Not sure if it would work for your situation. – woz Nov 01 '12 at 14:05
  • Not previously, but I have now. Thanks! The solution given there does not seem to work. I tested zvona's link (http://www.hakoniemi.net/labs/linkkitesti.html) in iOS Chrome, and the link therein opened a new URL, but it did not switch to Safari. – jonS90 Nov 01 '12 at 14:47
  • 3
    Unlike Chrome, Safari doesn't seem to have a documented URL-scheme for cross-app communication http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899. If you are developing your own app, you can implement application's delegate `openURL:`. If you are interested in JS alone, there's no documented way to do this. – A-Live Nov 01 '12 at 15:07
  • chrome must support url scheming before that. can you call facebook from chrome like facebook://... – Uğur Özpınar Dec 21 '12 at 10:16
  • Yes it does. For example, "waze://" succeeded in opening the waze app from Chrome ("facebook://" specifically was not a supported URL). Typed into the omnibar, it would simply become a google query. But as a link, yes it works. Thanks for the info guys. I am unfortunately interested in a JS method alone. – jonS90 Jan 10 '13 at 01:42

1 Answers1

5

The answer is yes. Courtesy or MacStories (http://www.macstories.net/tutorials/chrome-for-ios-send-a-webpage-back-to-safari-via-bookmarklet/), I found this code:

window.location='googlechrome-x-callback://x-callback-url/open/?url='+encodeURIComponent(location.href)+'&x-source=Safari&x-success='+encodeURIComponent(location.href);

Execute that code, go to your homescreen, reopen Chrome, and there's a magical back button to go back to Safari. This may not be exactly what you want, but it works... Kink of.

Good luck!

Update: Here's a screenshot: Link (Sorry, I don't have enough reputation to put it right in the post): https://i.stack.imgur.com/OR175.jpg

Update:
It seems that the functionality to do this has broken. Thank you!

Zoyt
  • 4,809
  • 6
  • 33
  • 45
  • is this 'hack' still working? as of 15th July 2014, my Mobile Safari opens the location.href in a new tab instead of Safar. – Metaphox Jul 15 '14 at 16:37
  • @Metaphox - Did you follow the special instructions at http://www.macstories.net/tutorials/chrome-for-ios-send-a-webpage-back-to-safari-via-bookmarklet/? There's a good chance it was removed, but I'll test it. – Zoyt Jul 15 '14 at 17:23
  • 4
    @Metaphox - It seems this functionality was removed. Sorry. – Zoyt Jul 15 '14 at 17:29