It is necessary to show different information depending on the operating system (windows or mas). How can this be done?
1 answer
User's OS can be found in several ways:
Get from the header of the
HTTP_USER_AGENT
request that comes from the user. And depending on this, render jsp.Use javascript:
var OSName="Unknown OS"; if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux"; document.write('Your OS: ' + OSName);
- Yes Spring-MVC. Can't find out right in jsp? Because of one line, I do not want to make another page. - Helena2977
- You can do it through javascript, but then the dynamics associated with the OS should also occur via js - MichaelPak
- What does it mean that the dynamics should occur through js? I tried this: <c: set var = "clientOs" value = "$ {navigator.appVersion}" />, but received an empty string. - Helena2977
- I don't know java script, unfortunately. If I make such a function, then where to insert it? - Helena2977
- You have a client-server interaction with the user: the client throws a request to the server, the server returns a ready-made
jsp
-jsp
in response. And you have two options: either get the user's OS from the request, renderjsp
and give it to the user, or give the finishedjsp
user, and find out the OS in thejavascript
browser and find out the necessary information that depends on the OS. - MichaelPak
|