Skip to content

Instantly share code, notes, and snippets.

@h4
Created March 27, 2012 13:34
Show Gist options
  • Save h4/2215903 to your computer and use it in GitHub Desktop.
Save h4/2215903 to your computer and use it in GitHub Desktop.
JS. Объект String
// 1. Методы объекта String
var str="Hello world!";
document.write(str.length);
document.write("<p>Bold: " + str.bold() + "</p>");
document.write("<p>Italic: " + str.italics() + "</p>");
document.write(str.match("world") + "<br />");
document.write(str.match("World") + "<br />");
document.write(str.indexOf("Hello") + "<br />");
document.write(str.indexOf("world"));
var str="Visit Microsoft!";
document.write(str.replace("Microsoft","W3Schools"));
// 2. Определение типа операционной системы
function sniffOs() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("win") != -1) {
return "Windows";
} else if (ua.indexOf("linux") != -1) {
return "Linux";
} else {
return "Computers";
}
}
document.write(sniffOs());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment