使用 javascript 在文本区域中设置文本

发布于 2024-12-23 02:41:35 字数 1348 浏览 1 评论 0原文

我正在尝试处理 textarea 中的文本 [在 Facebook 群组页面上。 “写帖子”有一个文本区域]并将其替换为新文本。这是使用 Greasemonkey 脚本完成的,

textHolder = document.getElementsByClassName( "uiTextareaAutogrow input mentionsTextarea textInput" )[0];

var vntext=textHolder.value;

var vn2text=Encrypt(vntext);

textHolder.value=vn2text;

因此在文本区域中可以看到新文本,但是当单击“发布”按钮时,不会采用新文本,而是发布旧文本

但是如果我们手动将至少一个字符插入到处理后的文本中,那么单击发布按钮后将发布结果文本。所以我不明白为什么它不直接获取新文本而不手动插入文本。

textarea 元素中还调用了其他事件,但我不知道它们到底在做什么。

那么应该怎么做才能发布新文本呢?

Facebook 页面上文本区域的 DOM 如下:

<textarea 
    class="uiTextareaAutogrow input mentionsTextarea textInput DOMControl_placeholder" 
    title="Write something..." name="xhpc_message_text" placeholder="Write something..." 
    onfocus="return wait_for_load(this, event, function() {if (!this._has_control) { new TextAreaControl(this).setAutogrow(true); this._has_control = true; } return wait_for_load(this, event, function() {JSCC.get('j4ef51acb72eb241587530255').init(JSCC.get('j4ef51acb72eb241587530256'));;JSCC.get('j4ef51acb72eb241587530256').init(["buildBestAvailableNames","hoistFriends"]);JSCC.get('j4ef51acb72eb241587530253').init({"max":10}, null, JSCC.get('j4ef51acb72eb241587530255'));;;});});" 
    autocomplete="off" style="direction: ltr; "
>
    Write something...
</textarea>

I am trying to process the text in textarea [on Facebook group page. 'write post' has one text area] and replace it with new text. This is done using Greasemonkey script

textHolder = document.getElementsByClassName( "uiTextareaAutogrow input mentionsTextarea textInput" )[0];

var vntext=textHolder.value;

var vn2text=Encrypt(vntext);

textHolder.value=vn2text;

So new text is seen in text-area but the when the 'post' button is clicked the new text is not taken instead old text is posted

But if we manually insert at least a character to the processed text then the resulting text is posted after click on post button. So I am not getting why it is directly not taking the new text without inserting the text manually.

There are other events being called in textarea element, but I do not know what they are doing exactly.

So what should be done so that new text will be posted?

DOM for text-area on Facebook page is as follows:

<textarea 
    class="uiTextareaAutogrow input mentionsTextarea textInput DOMControl_placeholder" 
    title="Write something..." name="xhpc_message_text" placeholder="Write something..." 
    onfocus="return wait_for_load(this, event, function() {if (!this._has_control) { new TextAreaControl(this).setAutogrow(true); this._has_control = true; } return wait_for_load(this, event, function() {JSCC.get('j4ef51acb72eb241587530255').init(JSCC.get('j4ef51acb72eb241587530256'));;JSCC.get('j4ef51acb72eb241587530256').init(["buildBestAvailableNames","hoistFriends"]);JSCC.get('j4ef51acb72eb241587530253').init({"max":10}, null, JSCC.get('j4ef51acb72eb241587530255'));;;});});" 
    autocomplete="off" style="direction: ltr; "
>
    Write something...
</textarea>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜访吸血鬼 2024-12-30 02:41:35

您可以链接到相关页面吗?

该页面可以在 JS 中跟踪该文本区域的值,甚至可以在每次击键时通过 AJAX 发布它。单击“发布”按钮可能只是告诉页面/服务器使用最后保存的文本版本。

由于 GM 脚本独立于鼠标和焦点事件更改文本区域值,因此不会触发页面和/或服务器跟踪机制。

因此,如果可以的话,找到合适的 JS 函数并在更改文本后调用它。

如果这太困难,请尝试将焦点设置到文本区域,然后到其他地方,然后返回到文本区域。

或者尝试将击键事件发送到文本区域。

链接到该页面或其完整代码快照,以获得更详细的帮助。

Can you link to the page in question?

That page could be tracking that textarea's value in JS or even AJAX-posting it with every keystroke. Clicking the 'post' button might merely tell the page/server to use the last saved version of the text.

Since the GM script changes the textarea value independently of mouse and focus events, the page and/or server tracking mechanism won't be triggered.

So, if you can, find the appropriate JS function and call it after changing the text.

If that's too difficult, try setting the focus to the textarea, then elsewhere and then back to the textarea.

Or try sending a keystroke event to the text area.

Link to the page, or a full-code snapshot of it, for more detailed help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文