简体   繁体   English

在桌面上为iframe设置移动用户代理

[英]Setting mobile user agent for iframe on desktop

I am attempting to use an iframe to preview the mobile version for a site that will be displayed on the desktop site. 我正在尝试使用iframe预览将在桌面网站上显示的网站的移动版本。 However the site that I am attempting to display does not use the screen size to activate the mobile version but rather a user agent. 但是,我尝试显示的站点未使用屏幕尺寸来激活移动版本,而是使用了用户代理。 Will I be able to somehow make the iframe request the site based of a mobile user agent such as 'Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'? 我能否以某种方式使iframe请求基于移动用户代理的网站,例如'Mozilla / 5.0(Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build / ICL53F)AppleWebKit / 534.30(KHTML,像Gecko)版本/4.0 Mobile Safari / 534.30'?

Your question is marked with both Javascript and PHP tags, two quite different languages, one client-side, the other server-side, respectively. 您的问题同时标有Javascript和PHP标记,这两种语言截然不同,一个客户端,另一个服务器端。 Changing the UserAgent string cannot be done with Javascript. 更改UserAgent字符串无法使用Javascript完成。 It could be done with a HTTP header set by PHP running on a proxy server between your browser and the site that will load in the iFrame. 这可以通过PHP设置的HTTP标头完成,该标头运行在浏览器和将加载到iFrame中的站点之间的代理服务器上。

On the other hand, if you use node.js server-side, you may be able to set the userAgent header with Javascript (a related OS Q&A may help). 另一方面,如果在服务器端使用node.js,则可以使用Javascript设置userAgent标头( 相关的OS Q&A可能会有所帮助)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM