Created
June 14, 2024 14:48
-
-
Save enniosousa/79d7c9e4f9b02031453850e1a99fcdf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Parent Document</title> | |
<script> | |
/** | |
* @link https://dev.to/admitkard/google-docs-url-tricks-and-tips-4d44 | |
* @link https://web.archive.org/web/20240523160018/https://dev.to/admitkard/google-docs-url-tricks-and-tips-4d44 | |
*/ | |
function createOrGetIframe() { | |
var iframe = document.getElementById('myIframe'); | |
if (!iframe) { | |
iframe = document.createElement('iframe'); | |
iframe.id = 'myIframe'; | |
iframe.width = '100%'; | |
iframe.height = '600px'; | |
iframe.frameborder = '0'; | |
document.body.appendChild(iframe); | |
} | |
return iframe; | |
} | |
const docId = '1VduggFiOAmWcfNi2rO86FIZbzAbpGxkGOv2c10LLQ5U'; | |
const editUrl = `https://docs.google.com/document/d/${docId}/edit`; | |
const previewUrl = `https://docs.google.com/document/d/${docId}/preview`; | |
function editor(type) { | |
const u = new URL(editUrl); | |
u.searchParams.set('widget', true); | |
// adicione o email do usuario que faz edição para evitar problemas de permissão | |
// caso o usuario faça login com uma conta não primária no navegador | |
// u.searchParams.set('authuser', '[email protected]'); | |
/** | |
* rm param values: | |
* The editor is composed by titlebar, menubar, toolbar | |
* options and their effects are as follows: | |
* - embedded: includes all | |
* - demo: includes the menubar, toolbar | excludes the titlebar | |
* - minimal: excludes all | |
*/ | |
u.searchParams.set('rm', type); | |
var iframe = createOrGetIframe(); | |
iframe.src = u.toString(); | |
} | |
function preview() { | |
var iframe = createOrGetIframe(); | |
iframe.src = previewUrl; | |
} | |
</script> | |
</head> | |
<body onload="preview"> | |
<h1>This is the parent document</h1> | |
<button type="button" onclick="editor('embedded')">Editor (embedded)</button> | |
<button type="button" onclick="editor('demo')">Editor (demo)</button> | |
<button type="button" onclick="editor('minimal')">Editor (minimal)</button> | |
<button type="button" onclick="preview()">Preview</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment