The top letter of the first line of lines in IE7

actualizarTituloWeb('brand name - '+seccion.toLowerCase().replace(/(?:_| |\b)(\w)/g, function(str, p1) { return p1.toUpperCase()})); 

Where

 function actualizarTituloWeb(titulo){ $( 'title' ).html ( titulo ); } 

Also tried with:

 function actualizarTituloWeb(titulo){ titulo = titulo[0].toUpperCase() + titulo.substring(1); titulo = titulo.toLowerCase(); $( 'title' ).text ( titulo ); return false; } 

and seccion has values โ€‹โ€‹like 'Reserva', 'ofertas', ..

Iโ€™m not sure why it doesnโ€™t work, but this actually leads to the failure of the whole script (you can test it in live here: http://toniweb.us/gm2 ) in IE7, and the title of the current document is not updated.

any idea what i'm missing?

-Edit -

I just realized that the problem is in this line! why?

 titulo = titulo[0].toUpperCase() + titulo.substring(1); 

Note: We cannot use CSS to achieve this, because it will be used for document.title

+4
source share
3 answers

In JScript <= 5.7 (IE 7), you cannot access a string like an array. Instead, you should use String.charAt() . Massive access is standardized in ES 5.

 titulo = titulo.charAt(0).toUpperCase() + titulo.substring(1); 

In addition, $('title').text(titulo); fighter does not work. In IE prior to version 8, you cannot set (or get) a title using the textContent title element.

 <html> <head> <title>test</title> </head> <body> <script type='text/javascript'> document.getElementsByTagName('title')[ 0 ].firstChild // null in IE <= 8 // IE 9 (and other browser): text node with nodeValue 'test' </script> </body> </html> 

use document.title

 document.title = titulo; 
+5
source

With a slight modification to the regex pattern, the expected behavior will be achieved

 actualizarTituloWeb('brand name - ' + seccion.toLowerCase().replace(/(^|\s|\-)(.)/gi, function(c) { return c.toUpperCase()})); 
+1
source

Why don't you do something like:

 var str = "blah blah"; str = str.toLowerCase(); str = str[0].toUpperCase() + str.substring(1); document.title = str; 
0
source

Source: https://habr.com/ru/post/1386269/


All Articles