I am creating a web-app where I need to truncate overflowing text. Mean I want to display text into some width ( say 90% of original width) and then want to trim my text if it occupies more space. If I need to trim any text then i will put ellipse (...) at the end of the text.
I have tried below three approaches.But could not get any which could work on all devices.
1- I tried with CSS based solution.
{
overflow: hidden;
text-overflow: ellipsis;
width:90%;
}
or
{
overflow: hidden;
text-overflow: ellipsis;
width:200px; //somewhere suggested to use with in px rather than %(just tried)
}
But it is not working properly. Then after googling I come to know that text-overflow CSS actually not work well in android phones.
2- I have tried with window.devicePixelRatio and screen.availWidth two methods. But "screen.availWidth" do not give proper screen size in Nexus4.
var device_width = screen.availWidth;
var device_density = window.devicePixelRatio;
3- I have created my own algorithm of trimming title. Which also not work on some devices like micromex and samsung GT-S6802.I am using ow/dd and oh/dd where ow = original_width , oh= original_height and dd= device_density.
I think that there is some difference between physical device pixel and programming pixel(may be a wrong term).I could not use mobile_js as it is not production ready.Still I will try to explore it too to find out some solution.
But if anyone have faced such problem of truncating the text according to device with ( say 90% of device with) then please let me know.It will be of great help.
Although currently I am looking for solution for android devices only but it will be great if the solution can work on ios too.