iPhone: Close Safari and return to homescreen using a script?

本秂侑毒 提交于 2019-12-12 03:29:32

问题


I have a .html-file that loads a javascript when loaded. I use this to turn on/off electronics in my home.

Currently I have saved the link on my homescreen (iPhone), and I have set the window to close automatically after 1 second of it being opened (which is enough for my javascript to run).

However, I think it would be much more cool, if I somehow could get Safari to close after closing the window. In that way I could return to my homescreen, so I wouldn't have to touch the homebutton, and thereby using this link as a sort of "switch" on my homescreen to turn on/off my electronics.

I have thought of using some code like:

function redirection() {
var userAgent = window.navigator.userAgent;
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
    window.location = "myapp://"    
}
}
</script>

But this would require a URL Scheme for the dashboard, which I don't think exist (?).

Do you have any other suggestions or is this task just not possible to perform? :)

Thanks in advance


回答1:


Apple doesn't have an approved way to exit an application, especially not one of their applications, like Safari. Like the Hotel California, you can launch another application, but you can never leave.



来源:https://stackoverflow.com/questions/14739013/iphone-close-safari-and-return-to-homescreen-using-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!