以紧凑形式打开Goog​​le文档/切换为紧凑形式 [英] Open google document in a compact form / switching to a compact form

查看:91
本文介绍了以紧凑形式打开Goog​​le文档/切换为紧凑形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我将一个Google文档加载到一个单独的div中. Google文档界面包括一个按钮,可隐藏菜单和 将视图切换为更紧凑的形式.

In my project I load a google document into a separated div. Google document interface includes a button which hides the menu and switches the view to a more compact form.

我的问题是-是否可以使用javascript切换到紧凑视图?

My question is - is it possible to switch to a compact view with the javascript?

我可以在预览模式下打开文档 https://docs.google.com/spreadsheets/d//preview 但这不是很有用(紧凑模式要好得多)

I can open document in a preview mode https://docs.google.com/spreadsheets/d//preview but it is not very usefull (compact mode is much better)

负责切换到紧凑视图的按钮的ID为 viewModeButton ,但是以下方法无效:

Button that is responsible for switching to compact view has the id viewModeButton but the following method does not work:

$("#viewModeButton").trigger('click');

推荐答案

答案:

由于同源政策,无法执行JavaScript代码来与iframe中未共享的域中的内容进行交互.

您似乎已经发现,同源策略是一项重要的Web应用程序安全策略,其历史可以追溯到1995年,该策略限制了一个网页的脚本执行不能与另一个 进行交互网页共享域 .

As it appears you have already discovered, the same-origin policy is a critical web application security policy dating back to 1995 which restricts the execution of scripts from one web page from interacting with another unless the two webpages share the domain.

http://subdomain.domain.com/some/path.htmlhttp://subdomain.com/som/other/path.html将能够彼此交互,因为协议,端口和域都在它们之间共享.但是,更改其中任何一个都会导致脚本交互失败:

http://subdomain.domain.com/some/path.html and http://subdomain.com/som/other/path.html would be able to interact with each other under this policy as the protocols, ports, and domains are all shared between them. Changing any of these though, would result in a failure of the script interaction:

使用示例域http://subdomain.domain.com/path.html:

Using the example domain http://subdomain.domain.com/path.html:

  • http://subdomain.domain.com/path2.html将起作用,因为只有路径不同.
  • https://subdomain.domain.com/path.html无效,因为协议不同.
  • 由于端口不同,
  • http://subdomain.domain.com:894/path.html起作用.
  • http://subdomain2.domain.com/other-path.html工作,因为主机不同.
  • http://subdomain.domain.com/path2.html will work as only the path differs.
  • https://subdomain.domain.com/path.html will not work as the protocols differ.
  • http://subdomain.domain.com:894/path.html will not work as the ports differ.
  • http://subdomain2.domain.com/other-path.html will not work as the hosts differ.

注意:Internet Explorer有一些例外情况,即在仅端口不同的情况下,或者如果两个域是Intranet域,但这是非标准的,则将运行脚本.

Note: Internet Explorer has a couple of exceptions where scripts will run for the cases where only the ports differ, or if the two domains are intranet domains, but this is non-standard.

对于像您这样的情况,如果脚本访问其他域以进行点击仿真或警报弹出窗口是相对良性的;但是在其他情况下,如果个人识别码或数据支付信息正在存储或传输,则严格分隔两个域对于将私人信息设为私人.

For cases like yours, it is relatively benign if scripts access other domains for click emulation or alert popups - but in other cases where personally identifiable or data payment information is being stored or transmitted, strict separation of the two domains is important to keep private information private.

  • Same-origin policy - MDN web docs
  • The Document Object Model (DOM) - MDN web docs
  • Make Google Docs, Sheets, Slides & Forms public

这篇关于以紧凑形式打开Goog​​le文档/切换为紧凑形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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