Objetos do Navegador
Integrando JS e HTML
/codes/w3c/browser-objects/hello-js/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="js/index.js"></script>
</head>
<body>
<h1 onclick="hello('Event')">Running Javascript</h1>
<script>
hello('Body Script');
</script>
</body>
</html>
/codes/w3c/browser-objects/hello-js/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="js/index.js"></script>
</head>
<body>
<h1 onclick="hello('Event')">Running Javascript</h1>
<script>
hello('Body Script');
</script>
</body>
</html>
/codes/w3c/browser-objects/hello-js/js/index.js
function hello(origin) {
console.log(`Hello ${origin}!`);
}
hello('Head Script');
/codes/w3c/browser-objects/hello-js/js/index.js
function hello(origin) {
console.log(`Hello ${origin}!`);
}
hello('Head Script');
Web APIs
- Standards
- Web APIs (MDN):
- BOM
Window
Window Hierarchy
Window.innerWidth
const width = window.innerWidth;
console.log(width);
const width = window.innerWidth;
console.log(width);
Window.alert()
window.alert('Hello world!');
window.alert('Hello world!');
Window.confirm()
const response = window.confirm('Is this JavaScript?');
console.log(response);
const response = window.confirm('Is this JavaScript?');
console.log(response);
Window.prompt()
const name = window.prompt('What is your name?');
console.log(name);
const name = window.prompt('What is your name?');
console.log(name);
Window.close()
window.close();
window.close();
Window.open()
const windowRef = window.open('https://developer.mozilla.org/');
const windowRef = window.open('https://developer.mozilla.org/');
Window.print()
window.print();
window.print();
Location
Location.href
location.href = 'http://www.ifpb.edu.br/noticias';
location.href = 'http://www.ifpb.edu.br/noticias';
Location.assign()
location.assign('http://www.ifpb.edu.br/');
location.assign('http://www.ifpb.edu.br/');
Location.reload()
location.reload();
location.reload();
History
History.back()
history.back(); // history.go(-1)
history.back(); // history.go(-1)
History.forward()
history.forward(); // history.go(1)
history.forward(); // history.go(1)
History.go()
history.go(-1)
history.go(1)
history.go(-1)
history.go(1)
Console
Console.clear()
console.clear()
console.clear()
Console.log()
const name = 'Alice';
console.log(name);
const name = 'Alice';
console.log(name);
Alice
> undefined
Alice
> undefined
Console.table()
const fruits = ["apples", "oranges", "bananas"];
console.table(fruits);
const fruits = ["apples", "oranges", "bananas"];
console.table(fruits);
Document
Document.body
const body = document.body;
console.log(body);
const body = document.body;
console.log(body);
Document.title
console.log(document.title);
console.log(document.title);
Document.getElementById()
const passwordElement = document.getElementById('password');
console.log(passwordElement.value);
const passwordElement = document.getElementById('password');
console.log(passwordElement.value);
Document.querySelector()
const passwordElement = document.querySelector('#password');
console.log(passwordElement.value);
const passwordElement = document.querySelector('#password');
console.log(passwordElement.value);
Document.querySelectorAll()
const inputs = document.querySelector('input');
Array.from(inputs).map(i => i.value);
const inputs = document.querySelector('input');
Array.from(inputs).map(i => i.value);
Document.write()
document.write('<h1>Lorem ipsum</h1>');
document.write('<h1>Lorem ipsum</h1>');