Created
March 20, 2012 13:20
-
-
Save h4/2135475 to your computer and use it in GitHub Desktop.
Подключение JavaScript на странице
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Подключение внешнего JS</title> | |
<!-- | |
Атрибут src указывает путь в файлу с javascript кодом | |
Атрибут type в настоящее время является необязательным | |
--> | |
<script | |
src="02.first-script.js" | |
type="text/javascript"></script> | |
</head> | |
<body> | |
<h1>Правильный способ подключения JS на странице</h1> | |
<!-- | |
Элемент script может располагаться в любом месте страницы | |
--> | |
<script | |
src="03.second-script.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Этот сценарий выведет текст в модальное всплывающее окно | |
*/ | |
alert('Скрипт работает'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
А этот сценарий выведет текст в консоль отладчика | |
*/ | |
// Заглушка для старых браузеров | |
if (!window.console || !console.firebug) { | |
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; | |
window.console = {}; | |
for (var i = 0; i < names.length; ++i) { | |
window.console[names[i]] = function() {} | |
} | |
} | |
console.log("И этот скрипт тоже работает"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Встроенный JS</title> | |
<script> | |
// JavaScript-код может быть размещён внутри блока script | |
document.write("Вывод текста прямо в браузер"); | |
</script> | |
</head> | |
<body> | |
<h1>Допустимый способ подключения JS на странице</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Обработчик события JS</title> | |
</head> | |
<body onload="alert('Страница загружена');"> | |
<h1>Нежелательный способ подключения JS на странице</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Обработчик события JS</title> | |
</head> | |
<body> | |
<h1>Недопустимый способ подключения JS на странице</h1> | |
<p><a href="javascript:alert('Ну кто так делает, а?');">Давай, щелкай</a></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment