Javascript 到 return content/string 不适合给定的 UIWebView 宽度和高度
Javascript to return content/string which doesn't fit in given width and height of UIWebView
假设我的 div,
中有一些字符串
"This is a dummy text inside my html.This is just a test".
然后我会将它加载到 UIWebView,其中我的 webview width=100,height=20.Now 假设只有 "This is a dummy text inside" 适合 webview。
现在我想要我的 javascript 到 return 我剩下的字符串 "my html.This is just a test"(因为高度太小不适合) .
这里我不想调整我的 webview 的大小,我只想要不适合我的 UIWebView 的剩余字符串。
如有任何建议,我们将不胜感激...
***I'm newbiew to javascript...
使用 Below JS 函数..它将 return 溢出文本..
示例:
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>
假设我的 div,
中有一些字符串"This is a dummy text inside my html.This is just a test".
然后我会将它加载到 UIWebView,其中我的 webview width=100,height=20.Now 假设只有 "This is a dummy text inside" 适合 webview。
现在我想要我的 javascript 到 return 我剩下的字符串 "my html.This is just a test"(因为高度太小不适合) .
这里我不想调整我的 webview 的大小,我只想要不适合我的 UIWebView 的剩余字符串。
如有任何建议,我们将不胜感激...
***I'm newbiew to javascript...
使用 Below JS 函数..它将 return 溢出文本..
示例:
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>