【问题标题】:Using Google Extensions to Copy and Paste into Wordpress使用 Google Extensions 复制和粘贴到 Wordpress
【发布时间】:2016-04-04 23:41:03
【问题描述】:

我正在创建一个从一页复制文本的 Chrome 扩展程序。我想将内容发布到 Wood Press 中的文本视图,该视图具有以下 HTML:

<div id="content-textarea-clone" class="wp-exclude-emoji" style="font-family: Consolas, Monaco, monospace; font-size: 13px; line-height: 19.5px; white-space: pre-wrap; word-wrap: break-word; width: 517px;">Test&amp;nbsp;</div>

我尝试使用以下方法更新此 div 的内容:

var art = document.getElementById("content-textarea-clone")
art.innerHTML = '<p>blah blah</p><p>blah blah blah</p>

无论我尝试什么都行不通。就像内容正在被重置。我的猜测是这个页面中有一些 javascript 正在以某种方式重置这个内容。有没有办法让我在不重置的情况下更新元素 content-textarea-clone 的内容?

【问题讨论】:

  • DOM和渲染页面有什么关系?

标签: wordpress google-chrome-extension


【解决方案1】:

这在某种程度上与get selected/highlighted text html in gmail compose mail area 有关。如回答,您将需要复制命令:

var copyText = document.execCommand('copy');

然后粘贴:

$('#text-to-display').val(""); //reset textbox value
$('#text-to-display').focus(); //set focus to textbox
document.execCommand("Paste");

另请注意,在使用大多数 Chrome API 时,您的扩展程序或应用程序必须在 manifest 的“权限”字段中声明其意图。每个权限都可以是已知字符串列表之一,例如托管应用程序所需的“clipboardWrite”,建议用于扩展程序和打包应用程序,如Declare Permissions 中所述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多