How to calculate the length (in pixels) of a string in JavaScript?
Given the new information that you want to add an ellipsis for text overflow, I think the CSS overflow property is the best approach. See this quirksmode article for more information: http://www.quirksmode.org/css/textoverflow.html
you can use simple code
var canvas = document.createElement('canvas'); var ctx = canvas.getContext("2d"); ctx.font = "11px Arial"; var width = ctx.measureText(str).width;
A working simshaun suggestion example: http://jsfiddle.net/tycjf/2/
The easiest way is to write it to a range on the page, get the width, and then delete the range. Also, this is relative to any font size that inherits a range.
Source: https://habr.com/ru/post/1344280/More articles:How to convert NSDecimal to NSString with custom format - objective-cHow to make this thread safe - thread-safetySlow polling of touch messages on Android via browser and native application - javascriptHow to get 64x64 file type / extension icon in C #? - c #How to track a leak of a Windows USER object? - c ++Database in the cloud? - performanceellipse text in yui datatable - javascriptPMT in Javascript - javascriptInstalling libxml-ruby gem fails because zlib is missing - ruby | fooobar.comCalculate page count using PHP Maths and Round - mathAll Articles