Google Apps Script How to link to JS or CSS file on Google Drive

落爺英雄遲暮 提交于 2019-12-04 10:48:42

问题


Can I keep style.css or anyscript.js hosted on a folder on Google Drive and then include the script with a link to the file in Drive? If so.. how?

And here I mean GAS for use on Google Sites... so the script is not located in Google Drive


回答1:


UPDATE: As of August 31, 2015 this technique has been deprecated by Google.

Google recent made it possible host a file publicly on Google Drive:

  1. Create a folder in Google Drive
  2. Put any files you want to access publicly in the folder
  3. Share it publicly (needs to be "Public on the web") and copy the folder ID from the "Link to Share". For example, the folder ID from this link: https://docs.google.com/folder/d/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/edit ... is: 0B5AR8ct5SZfSTDZTQjNNVXR4RWM
  4. The URL for each file will be https://googledrive.com/host/ followed by the folder id followed by the filename. For example: if you saved style.css in the folder in step #1: https://googledrive.com/host/0B5AR8ct5SZfSTDZTQjNNVXR4RWM/style.css



回答2:


Google seem to have changed it.

At the time of writing, a link to the raw data works with the following link format:

https://drive.google.com/uc?id=YOUR_DOCUMENT_ID




回答3:


What about Google's own recommendation in the HTML Service Best practices, for Separating HTML, CSS and Javascript?




回答4:


It still works, the URLs just look a bit different. Answered already over here, but the steps are:

  1. On the folder with your intended file (e.g. FILE.css), hit Sharing Settings, then Advanced, then select "Public on the web - Anyone on the Internet can find and view."
  2. In the URL bar (or share link), copy everything after the drive.google.com/drive/u/0/folders/
  3. Use that ID to replace the XX-XXXXXXXXXXXXX in: http://googledrive.com/host/XX-XXXXXXXXXXXXX/FILE.css
  4. Navigate to the appended URL in Step 3 and you will now see your raw data.

Credit to @chris.huh at: https://productforums.google.com/forum/#!topic/drive/MyD7dgLJaEo



来源:https://stackoverflow.com/questions/15110264/google-apps-script-how-to-link-to-js-or-css-file-on-google-drive

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