我可以动态更改 mobile safari 中的视口元标记吗?
我有一个为移动 Safari 浏览器构建的 AJAX 应用程序,需要显示不同类型的内容。
对于某些内容,我需要 user-scalable=1
,对于其他内容,我需要 user-scalable=0
。
有没有办法在不刷新页面的情况下修改content属性的值?
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
I have an AJAX app built for mobile Safari browser that needs to display different types of content.
For some content, I need user-scalable=1
and for other ones, I need user-scalable=0
.
Is there a way to modify the value of the content attribute without refreshing the page?
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我意识到这有点老了,但是,是的,这是可以做到的。一些帮助您入门的 JavaScript:
只需更改您需要的部分,Mobile Safari 就会遵循新的设置。
更新:
如果您在源代码中还没有元视口标签,您可以直接添加如下内容:
或者如果您使用的是 jQuery:
I realize this is a little old, but, yes it can be done. Some javascript to get you started:
Just change the parts you need and Mobile Safari will respect the new settings.
Update:
If you don't already have the meta viewport tag in the source, you can append it directly with something like this:
Or if you're using jQuery:
在你的
的
某个地方在你的 javascript 中
......但是祝你好运,为你的设备调整它,摆弄几个小时......但我仍然不在那里!
来源
in your
<head>
somewhere in your javascript
... but good luck with tweaking it for your device, fiddling for hours... and i'm still not there!
source
这个问题大部分已经得到解答,但我将扩展...
第 1 步
我的目标是在某些时间启用缩放,并在其他时间禁用它。
第 2 步
视口标签将更新,但捏缩放仍然处于活动状态!我必须找到一种方法让页面接受更改...
这是一个黑客解决方案,但是切换主体的不透明度就可以解决问题。我确信还有其他方法可以实现这一目标,但这对我有用。
第 3 步
此时我的问题已基本解决,但还没有完全解决。我需要知道页面的当前缩放级别,以便我可以调整某些元素的大小以适合页面(想想地图标记)。
我希望这对某人有帮助。我花了几个小时敲击鼠标才找到解决方案。
This has been answered for the most part, but I will expand...
Step 1
My goal was to enable zoom at certain times, and disable it at others.
Step 2
The viewport tag would update, but pinch zoom was still active!! I had to find a way to get the page to pick up the changes...
It's a hack solution, but toggling the opacity of body did the trick. I'm sure there are other ways to accomplish this, but here's what worked for me.
Step 3
My problem was mostly solved at this point, but not quite. I needed to know the current zoom level of the page so I could resize some elements to fit on the page (think of map markers).
I hope this helps somebody. I spent several hours banging my mouse before finding a solution.
试试这个
Try this