JavaScript来填补在一个网站上一个格式文本字段 [英] Javascript to fill a formatted text field on a web site

查看:143
本文介绍了JavaScript来填补在一个网站上一个格式文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道几乎一无所知的JavaScript。由猴子看,猴子-DO的方法,我已经设法成功地使用JavaScript的AppleScript / Safari浏览器中使用以下命令,以填补在一个网站的文本字段:

I know virtually nothing about Javascript. By a monkey-see, monkey-do approach I’ve managed to successfully use Javascript within AppleScript/Safari to fill text fields on a web-site using the following command:

do JavaScript "document.getElementById('ElementID').value ='TextToEnter';" in document 1

我已经能够将文本输入到各个领域,除了之一。这项工作被标记为输入类型的字段=TEXT。不工作的领域是复杂的,该输入的文本可以被格式化(粗体,斜体,下划线,入境后对齐等)假设我已经确定了正确的源$ C ​​$ C这个元素,它看起来如下之前的任何文本输入:

I’ve been able to enter text into all fields except one. The fields that work are labeled as input type="text". The field that doesn’t work is complex in that the entered text can be formatted (bold, italics, underline, alignment, etc.) after entry. Assuming I’ve identified the correct source code for this element it looks as follows PRIOR TO any text entry:

<body id="tinymce" class="mce-content-body " onload="window.parent.tinymce.get('fax_text').fire('load');" contenteditable="true" spellcheck="false"><p><br data-mce-bogus="1"></p></body>

根据其如何看待,有时 P BR 标签出现在独立的线路,但一切都在其它方面

Depending on how its viewed, sometimes the p and br tags appear on separate lines but everything is otherwise identical.

文字手动输入后(在这里插入文本),直接进入网页的文本字段源$ C ​​$ C变为:

After manual entry of text ("INSERT TEXT HERE") directly into the web page's text field the source code becomes:

<body id="tinymce" class="mce-content-body " onload="window.parent.tinymce.get('fax_text').fire('load');" contenteditable="true" spellcheck="false"><p>INSERT TEXT HERE</p></body>

以下没有工作(裹着的AppleScript):

The following did not work (wrapped in Applescript):

document.getElementById('tinymce').value ='INSERT TEXT HERE';

它产生错误:缺少值

It produces the error: "missing value".

按@WhiteHat中,其中n = 0-4插入的文本在页面上,但不是在针对文本字段几个点以下; N> 4最终形成了缺失值错误:

As per @WhiteHat, the following with n= 0-4 inserted text at several spots on the page but not in the targeted text field; n > 4 resulted in the "missing value" error:

document.getElementsByTagName('p')[n].innerHTML ='Insert text here';

我试着瞄准 BR 标签,但无济于事。如何确定目标的JavaScript这个文本字段?注:我并不需要输入文本的格式。

I tried targeting the br tag but to no avail. How do I target this text field with Javascript? Note: I do not need to format the entered text.

推荐答案

这文本字段在的iFrame
此iFrame中包含的 HTML文档&LT; HTML&GT;&LT; HEAD&GT;&LT;身体GT; )。

要得到这个文件,你需要the_iFrame。 contentDocument

To get this document, you need the_iFrame.contentDocument.

do JavaScript "var ifr = document.getElementById('fax_text_ifr'); ifr.contentDocument.getElementsByTagName('p')[0].innerHTML = 'some text';" in document 1

这篇关于JavaScript来填补在一个网站上一个格式文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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