Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any drawbacks when setting the HTML lang attribute dynamically on the client side?

We are currently serving the initial index page for a single page application without the lang attribute set on the HTML tag. At the moment we are also not setting it dynamically after the page is loaded.

Are there any problems with screen readers if the language is set dynamically instead of already setting it on the initial page?

like image 943
Robert M. Avatar asked Mar 08 '17 10:03

Robert M.


1 Answers

Modern screenreaders understand javascript and use the javascript modified DOM instead of the initial DOM.

As long as you do not change the lang attribute too late (after the screenreader already started to speak), it should work.

Note that switching language might result in some bugs if you do not also change the current URL using the HTML5 api history.

like image 50
Adam Avatar answered Nov 14 '22 22:11

Adam