PDA

View Full Version : Title problem in IE



gce
11-10-2008, 08:47 PM
Hi,

I'm trying to show a tooltip in IE using the title attribute.

The problem is the text is carried over to a new line not at the right positions, but arbitrary by IE.

I found I can control this by replacing spaces with   in the text - title="test text..."

The problem is this is not possible using JS :

element.title = "test text...";

is not working.

Why is it not working ? How to resolve this problem ?

Thanks

clueful
11-10-2008, 08:57 PM
Try: element.title = "test\xA0text...";

gce
11-11-2008, 06:35 AM
This is not working.

jscheuer1
11-11-2008, 12:09 PM
Please post a link to the page on your site that contains the problematic code so we can check it out.

gce
11-11-2008, 12:51 PM
It's an intranet site.

But I'm testing with the following code :

<html>
<script type="text/javascript">
function repl()
{
var str = "text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text";
document.getElementById("anch").title = str;
}
</script>
<body>
<a id="anch" title="text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text&nbsp;text">text<a/>
</body>
</html>

As I explained if I set the title attribute directly in <a> the tooltip is on a single line as I want. But I need to set it using js and it is not working.

jscheuer1
11-11-2008, 01:24 PM
Try: element.title = "test\xA0text...";

Works here:


<html>
<script type="text/javascript">
function repl()
{
var str = "text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2";
document.getElementById("anch").title = str;
}
</script>
<body>
<a id="anch" onclick="repl();" title="text1&nbsp;text1&nbsp;text1&nbsp;text1&nbsp;text1&nbsp;text1&nbsp;text1&nbsp;text1&nbsp;text1&nbsp;text1">text<a/>
</body>
</html>

gce
11-11-2008, 02:49 PM
Yes, actually it works.

Thank you very much !

gce
11-11-2008, 03:55 PM
Still one problem though :

In Firefox it looks like \xa0 is working, but I try \x0a which should be new line and it is not working. Do you know some resolution ?

jscheuer1
11-11-2008, 04:20 PM
That won't work, for the same reason that this won't make a new line in a title:


<a title="Something that
breaks on a line break">What?</a>

It's filtered out. If IE does allow it, it is just a different way that it is handling the dynamically added title. FF is doing it as though it were hard coded.

If you need more control over the tool tip than title will allow across browsers, use a tool tip script.

One thing though, if the combined length of the title is great enough, it will wrap on a space in FF or IE:


var str = "text2\xa0text2\xa0text2 text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2\xa0text2";