【问题标题】:Javascript to return content/string which doesn't fit in given width and height of UIWebViewJavascript返回不适合UIWebView给定宽度和高度的内容/字符串
【发布时间】:2015-02-26 04:36:45
【问题描述】:

假设我的 div 中有一些字符串,

“这是我的 html 中的虚拟文本。这只是一个测试”

我会将它加载到 UIWebView,其中我的 webview width=100,height=20。现在假设只有 “This is a dummy text inside” 适合 webview。

现在我希望我的 javascript 将剩余的字符串返回给我“我的 html。这只是一个测试”(由于高度较低,不适合)。

在这里我不想调整我的 webview 的大小,我只想要不适合我的 UIWebView 的剩余字符串。

任何建议将不胜感激...

                                     ***I'm newbiew to javascript...

【问题讨论】:

    标签: javascript html ios objective-c uiwebview


    【解决方案1】:

    使用Below JS函数..它将返回溢出文本..

    示例:

    load_content('foo','Sample Text',30,100);
    
    
    <script type="text/javascript">
        function load_content(div_tag_id,content_string,height,width){
    
            var text_fit = "";
            var text_overflow = "";
            var string_array = content_string.split(" ");
    
            for(var i = 0; i < string_array.length; i++ ) {
    
                document.getElementById(div_tag_id).style.width = width+"px";
                document.getElementById(div_tag_id).innerHTML = document.getElementById(div_tag_id).innerHTML + " "+string_array[i];
                if(document.getElementById(div_tag_id).offsetHeight > height) {
                    text_overflow += " "+string_array[i];
                } else {
                    text_fit += " "+string_array[i];
                }
            }
            document.getElementById(div_tag_id).innerHTML = text_fit;
            return text_overflow;
    
        }   
    </script>
    

    【讨论】:

      猜你喜欢
      • 2015-03-20
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 1970-01-01
      • 2017-08-08
      • 2010-11-08
      • 1970-01-01
      相关资源
      最近更新 更多