【发布时间】:2020-10-30 07:01:38
【问题描述】:
在我的控制器中,我指定了我希望重定向到的 URL。
def redirect
@app_url = "myapp://something"
end
在html模板中,我尝试使用JS更改window.location。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>App Redirect</title>
<script type="text/javascript">
window.onload = function() {
const userAgent = window.navigator.userAgent;
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
window.location = <%= @app_url %>
}
}
</script>
</head>
<body>
<h1><%= @app_url %></h1>
</body>
</html>
但是,当我转到该页面时,app_url 按预期呈现为<h1>,但没有提示我打开移动应用程序。
但如果我改用window.location = "myapp://something",一切都会按预期进行,因为系统会提示我打开应用程序。
感谢任何帮助。
【问题讨论】:
标签: javascript html ios ruby-on-rails ruby