Chapter 10 : JavaScript Part 3 Flashcards
What information does the window.screen object contains?
- Information about the user’s screen
- It can be written without the window prefix
screen.width
screen.height
What value does screen.width returns?
- Returns the width of the visitor’s screen in pixels
What value does screen.height returns?
- Returns the height of the visitor’s screen in pixels
What value does screen.availWidth returns?
- Returns the width of the visitor’s screen ( pixels ), minus interface features like the windows taskbar
What value does screen.availHeight returns?
- Returns the height of the visitor’s screen ( pixels ), minus interface features like the windows taskbar
What value does screen.colorDepth returns?
- Returns the number of bits used to display 1 color
What value does screen.pixelDepth returns?
- Returns the pixel depth of the screen
Write a JavaScript code to view screen width and height with id demo and demo2?
<script> document.getElementById("demo").innerHTML = "Screen Width : " + screen.width; document.getElementById("demo2").innerHTML = "Screen Height : " + screen.height; </script>
<p></p>
<p></p>
Write a JavaScript code to view screen available width and height with id demo and demo2?
<script> document.getElementById("demo").innerHTML = "Screen Avail Width : " + screen.availWidth; document.getElementById("demo2").innerHTML = "Screen Avail Height : " + screen.availHeight; </script>
<p></p>
<p></p>
Write a JavaScript code to view color depth and pixel depth with id demo and demo2?
<script> document.getElementById("demo").innerHTML = "Color Depth : " + screen.colorDepth; document.getElementById("demo2").innerHTML = "Pixel Depth : " + screen.pixelDepth; </script>
<p></p>
<p></p>
What can window.location object be used?
- Used to get the current page address ( URL ) and to redirect the browser to a new page
- It can also be written without using the window prefix
window.location.href -> location.href
What does window.location.href do and what does it return?
- Returns the href ( URL ) of the current page
- http://www.apu.edu.my/index.html
What does window.location.hostname do and what does it return?
- Returns the domain name of the web host
- www.apu.edu.my
What does window.location.[athname do and what does it return?
- Returns the path and filename of the current page
- /explore-apu/university/index.html
What does window.location.protocol do and what does it return?
- Returns the web protocol used
- http : / https:
What does window.location.assign() do and what does it return?
- Loads a new document
- Loads a new document on current document
What object contains the browsers history?
- window.history
- It can also be written without the window prefix
List out 2 methods for how JavaScript can access user browsing history
- history.back()
- history.forward()
- There are some limitations to protect the privacy of the users
What are the time intevals called and what can it do?
- Timing Events
- Execution of code at specified time intervals
List out 2 key methods for Timing Events
- setTimeout ( function , milliseconds)
- Executes a function after waiting a specified number of milliseconds
- setInterval ( function, milliseconds )
- Same as setTimeout but repeats the execution of the function
<button>Try it</button>
<button>Try it</button>
- Can also use with window prefix
<button>Try it</button>
What does clearTimeout() do?
- Stops the execution of the function specified in setTimeout()
What is the syntax for clearTimeout?
- window.clearTimeout(timeoutVariable)
- clearTimeout(timeoutVariable)
- Uses the variable returned from setTimeout()
myVar = setTimeout(function, milliseconds);
clearTimeout(myVar);
- We can also stop the execution by calling the clearTimeout() method
What method can we use to stop the setInterval() method?
- clearInterval()
- myVar = setInverval( function, milliseconds );
clearInterval(myVar);
What does cookies do?
- Allow website to store user information in web page for faster login, performance
- Data stored in small text files , on user’s computer
What problem does cookies solved?
- How to remember information about the user
What JavaScript property is used to store cookies?
- document.cookie
How to create cookie to store username John Doe?
document.cookie = “username=John Doe”;
Set the cookie username John Doe and expiry date and then the path
document.cookie = “username=John Doe”; expires = Thu, 18 Dec 2017 12:00:00 UTC ; path=”/”;
What is the default value for path?
- By default, the cookie belongs to the current page
How to read the cookie?
var username = document.cookie;
- document.coockie will return all cookies in one string like
cookie1 = value ; cookie2 = value ; cookie3 = value