将文本拖放到Gas Web应用程序的iframe

时间:2019-08-16 19:32:12

标签: javascript iframe google-apps-script web-applications bookmarklet

我正在编码一个Google应用程序脚本,该脚本可将所选文本作为参数并通过小书签打开新窗口。我正在尝试select&drag&drop某些文本或指向Web应用程序input/textarea的链接,该文本可在打开的窗口示例中运行:https://script.google.com/macros/s/.../exec?article=

问题是当我允许将iframe与.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)一起使用并在iframe中添加https://script.google.com/macros/s/.../exec?article=页而不是在新页面中打开时; drag&dropping文本被禁用。无论如何,是否可以将文本拖放到iframe的输入框中?

drag&drop在常规https://script.google.com/macros/s/.../exec?article=页中可用,但在iframe中不可用。

还要感谢我在Firefox上尝试过该功能的评论,但仍然可以在Chrome上运行

GAS

function doGet(e) {
  return HtmlService.createHtmlOutput('')
    .append('<input type="text" id="kind" placeholder="Kind" size="4" value="' + (e.parameter.article?e.parameter.article:"") + '">')
  .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
  Logger.log(e);
}

书签打开新页面

javascript:if(window.getSelection)s=window.getSelection(); else if(document.getSelection)s=document.getSelection(); else if(document.selection)s=document.selection.createRange().text;     open('https://script.google.com/macros/s/...GAS.ID.../exec?article=article'+(location.host=='scholar.google.com'?'':'&pdf='+encodeURIComponent(location.href))+'&bib='+encodeURIComponent(s.toString())+'bib');0

添加iframe的书签

javascript:if(window.getSelection)s=window.getSelection();else if(document.getSelection)s=document.getSelection();else if(document.selection)s=document.selection.createRange().text;    iframe=document.body.appendChild(document.createElement('iframe'));iframe.style='position:fixed;bottom:0;z-index:99999;width:280px;'; iframe.src='https://script.google.com/macros/s/...GAS.ID.../exec?article=article'+(location.host=='scholar.google.com'?'':'&pdf='+encodeURIComponent(location.href))+'&bib='+encodeURIComponent(s.toString());0

*将“ /...GAS.ID.../”替换为书签中的Web应用程序ID

0 个答案:

没有答案