谷歌应用脚​​本:如何确定屏幕分辨率? [英] Google apps script: how to determine screen resolution?

查看:112
本文介绍了谷歌应用脚​​本:如何确定屏幕分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Google应用脚本中创建应用,但我想根据屏幕分辨率(移动和桌面)显示不同的布局。但是,我无法找到关于如何确定屏幕分辨率的任何信息。



当然,我无法从服务器端确定屏幕分辨率,所以我试过如果我可以用客户端处理程序做一些事情,但是 ClientHandlers 没有任何屏幕分辨率的方法。我还尝试使用 app.createHTML()添加手动客户端脚本到应用程序,但Google不允许使用createHTML包含JavaScript。



那么我怎样才能使用Google apps脚本来获得浏览器的分辨率呢?

解决方案 div>

在GAS环境中,JavaScript screen.witdth 属性不起作用。 Google Caja sanitizer在GAS的引擎下引发了
$ b


未捕获的脚本错误:源代码中的未定义屏幕 :
'tryit.asp?filename = tryjsref%5fscreen%5fwidth'at line:7
tryit.asp?filename = tryjsref%5fscreen%5fwidth:7:screen is not defined。


异常如果要将以下HTML页面加载到 Caja游乐场。可能它是Caja的一个问题。


$ b

 <!DOCTYPE html> 
< html>
< body>

< script>

document.write(Test);
document.write(Total Width:+ screen.width);

< / script>

< / body>
< / html>

可能的解决方法不是依赖屏幕分辨率,而是使用用户代理字符串。该字符串包含用户浏览器id。 UiApp.getUserAgent 方法将其返回。例如,桌面上的Mozilla Firefox提供了这样的字符串,例如 - Mozilla / 5.0(Windows NT 6.0; rv:15.0)Gecko / 20100101 Firefox / 15.0.1,gzip(gfe)。在手机上,该字符串包含 ...(Android; Mobile; rv:15.0)... 。检查过程在返回的字符串中搜索单词 Mobile Android 等。如果其中一个发现它是移动平台和主要代码使用相对控制尺寸绘制移动GUI。下面的代码演示了如何使用它:
$ b

  function doGet(e){
var app = UiApp.createApplication();
app.add(app.createLabel(UiApp.getUserAgent()));
返回应用程序;
}


I am trying to create an app in Google apps script, but I want to display different layouts depending on the resolution of the screen (mobile & desktop). However, I can't find anything about how to determine the screen resolution.

Of course I can't determine the screen resolution from the server side, so I tried if I could do something with clientside handlers, but the ClientHandlers don't have any method for screen resolution. I also tried to add a manual clientside script to the app using app.createHTML(), however Google doesn't allow to include javascript using createHTML.

So how can I get the resolution of the browser using Google apps script?

解决方案

The JavaScript screen.witdth property does not work in GAS environment. The Google Caja sanitizer, which is under the hood of GAS, throws the

Uncaught script error: 'screen is not defined.' in source: 'tryit.asp?filename=tryjsref%5fscreen%5fwidth' at line: 7 tryit.asp?filename=tryjsref%5fscreen%5fwidth:7: screen is not defined.

exception if to load the following HTML page to the Caja Playground. Probably it is an issue of Caja.

<!DOCTYPE html>
<html>
<body>

<script>

document.write("Test");
document.write("Total Width: " + screen.width);

</script>

</body>
</html>

A possible workaround is not to rely upon a screen resolution but to use a user-agent string. This string contains the user browser "id". The UiApp.getUserAgent method returns it. For instance, Mozilla Firefox on a desktop provides this string like - Mozilla/5.0 (Windows NT 6.0; rv:15.0) Gecko/20100101 Firefox/15.0.1,gzip(gfe). On a mobile phone this string contains ...(Android; Mobile; rv:15.0).... A check procedure searches in the returned string the words Mobile, Android, etc. If one of them found it is a mobile platform and the main code draws a mobile GUI using relative controls sizes. The following code shows how to use it

function doGet(e) {
  var app = UiApp.createApplication();
  app.add(app.createLabel(UiApp.getUserAgent()));
  return app;
}

这篇关于谷歌应用脚​​本:如何确定屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆