HTML文本区字符的限制内机器人的WebView [英] HTML TextArea Characters Limit Inside Android WebView

查看:95
本文介绍了HTML文本区字符的限制内机器人的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个HTML网页,其中有以下code。

I have written a HTML page which has following code.

<div id="adsListContainer" style="margin: 5px;">
    <textarea id="txtDesc" rows="20" cols="50"></textarea>
    <br />
    <input id="txtCounts" value="0" size="8" />
    <input type="button" value="Count" onclick="countChars()" />
</div>

上面的HTML被封闭在一个名为的test.html 文件,它被显示在Android的WebView控件。现在使用Java和web视图的使用loadURL()功能我执行JavaScript作为写的东西在文本区域如下code去。

The above html is enclosed in a file named test.html and it's being shown in android's WebView control. Now using Java and WebView's loadURL() function I am executing javascript as to write something in that textarea as following code goes.

javascript:document.getElementsByTagName("textarea")[0].value += 'anything goes here of not more than 50 chars';void(0);

甚至认为上述code ++工程,我叫了很多次,所以我可能在这个textarea元素插入7000+字符。

Even thought the above code works and I am calling it many times so I may insert 7000+ characters in this textarea element.

Java的code负责执行JavaScript是如下插入文本(HTML)到文本区域。

The Java code responsible for executing Javascript to insert text (HTML) into textarea is as follows.

int bStart = 0;
int bEnd = 49;
String description = "some huge description including html tags"
int totalChars = description.length() - 1;

while (bStart <= totalChars) {
    if (bEnd > totalChars)
        bEnd = totalChars;

    rv = "javascript:";

    rv += "var tas=document.getElementsByTagName('textarea');"; // description
    rv += "if (tas.length>0) {";
    rv += "var ta=tas[0];";
    rv += "ta.value += '"
           + description.substring(bStart, bEnd)
            .replace("'", "\\'").replace('"', '\"') + "';"; // description
    rv += "}";

    webView.loadUrl(rv + "void(0);");

    bStart += 50;
    bEnd += 50;
}

虽然上面的code ++工程,但不完全。描述有 7245 字符,但它只能插入 6267 字符到网页的文本区域。

Although the above code works but not perfectly. The description has 7245 characters but it only insert 6267 characters into textarea of the web page.

有我丢失的东西?

推荐答案

我试图只与HTML + JavaScript的应用您的问题。请参阅这个小提琴

I have tried to apply your issue only with HTML + JavaScript. Please see this fiddle.

正如你所看到的,这是正常工作。所以,我认为这个问题可能是更换转义序列。见你是从,这将增加说明变量的大小内环路改变转义序列字符。但是,totalChars具有是previously存储描述的大小的大小。所以,以后当你申请bStart&LT; = totalChars状态,它会计算,直到totalChars只(即已经小于当前大小)

As you can see, this is working properly. So, I think the issue may be with replacement of escape sequence characters. See that you are changing the escape sequence character from within the loop that will increase the size of description variable. But, totalChars has the size which is previously stored size of description. So, later when you apply "bStart <= totalChars" condition, it will count till the totalChars only (i.e. already less then the current size).

最后,你的描述有太多转义序列字符可能会产生这个问题。因此,更换整个字符串previously和放大器;然后添加子到你的Javascript。

Concluding, your description has too many escape sequences characters "may be" generating this problem. So, replace the whole string previously & then add substrings to your javaScript.

这可能会或可能不会解决你的问题,如果有任何一个又一个,还是。所以,请纠正我,如果我错了。

This may or may not solve your issue if there is any another one, still. So, please correct me if I am wrong.

感谢你。

这篇关于HTML文本区字符的限制内机器人的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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