JQuery Mobile with Google Apps Script

可紊 提交于 2019-11-29 02:23:15
Gil Sokolov
var output = HtmlService.createHtmlOutput('<b>Hello, world!</b>');
output.addMetaTag('viewport', 'width=device-width, initial-scale=1');

this will help

You can determine the size of the display via CSS Media Queries. For example, adding this to your CSS causes the form to display differently depending on the device's screen size:

@media only screen and (min-device-width: 413px) and (max-device-width: 415px) { /* iPhone 6+ */
  #main, #dialog {
   zoom: 3;
   background: red;
  }
}

@media only screen and (min-device-width: 374px) and (max-device-width: 376px) { /* iPhone6 Styles */
  #main, #dialog  {
   transform: scale(2);
    background: blue;
  }
}

@media only screen and (min-device-width: 359px) and (max-device-width: 361px) { /* iPhone6+ Alt Styles */
  #main, #dialog  {
   transform: scale(2);
    background: green;
  }
}

@media only screen and (min-device-width: 319px) and (max-device-width: 321px) { /* iPhone5 or less Styles */
  #main, #dialog  {
   transform: scale(2);
    background: grey;
  }
}

Using Chrome's device emulation, the form looked pretty good. (The red background is set by the above css.) But when I accessed the app from my real iPhone 6+, not all elements zoomed equally. (Submit button for example.) So there is likely some other specific css needed to further tailor the result.

David Watson

I had this exact problem. All I was trying to do is test some jQuery mobile templates for a website without deploying them to either Google App Engine or Google Cloud Storage.

Google Drive no longer lets you serve HTML directly, so the app script is the next best option.

The problem is that app scripts iframe everything, creating viewport problems for things meant to be viewed on mobile (even after fixing the problem where jQuery src= need to be https instead of http).

The fix is to have a META tag on the iframe page in addition to the HTML you're serving.

Anyway, the two answers that say to add a META tag worked great.

If you are serving a jQuery mobile page, this code.gs code worked for me:

function doGet() {
  var output = HtmlService.createHtmlOutputFromFile('test');
  output.addMetaTag('viewport', 'width=device-width, initial-scale=1');
  return output;
}

Where test is your test.html file.

This should help addmetatagname() of Class HtmlOutput. You should modify the meta tag through code.

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