How many create cookies in JavaScript?

JavaScript Cookies

Cookies are exposed as the cookie property of the Document object. This property is both readable and writeable.

You can see Cookies in Google Chrome by following chrome://settings/content/cookies

Creating Cookies

When you assign a string to document.cookie, the browser parses it as a cookie and adds it to its list of cookies. There are several parts to each cookies, many of them optional.

Syntax: –

document.cookie = “name=value”;
document.cookie = “name=value; expires=date; domain=domain; path=path; secure”;
document.cookie = “name=value; max-age=inSecond; domain=domain; path=path; secure”;

Ex:-

Creating Cookies

Optional Cookies Attribute:-

max-age
expires
domain
path
secure

Whenever you omit the optional cookie fields, the browser fills them in automatically with reasonable defaults.

max-age

It is used to create persistent cookies. It is supported by all modern browsers except IE.

Type of cookies: –

  • Session Cookies – Cookies that are set without the expires/max-age field are called session cookies. It is destroyed when the user quits the browser.
  • Persistent Cookies – The browser keeps it up until their expiration date is reached.

Ex:-

expires

It is used to create persistent cookies.

Type of cookies: –

  • Session Cookies – Cookies that are set without the expires/max-age field are called session cookies. It is destroyed when the user quits the browser.
  • Persistent Cookies – The browser keeps it up until their expiration date is reached.

Ex:-

document.cookie = “username=devops; expires=Monday, 3-Sep-2018 09:00:00 UTC”;

domain

It specifies the domain for which the cookie is valid. If not specified, this defaults to the host portion of the current document location. If a domain is specified, subdomains are always included.

Ex: –

path

Path can be / (root) or /mydir (directory). If not specified, defaults to the current path of the current document location, as well as its descendants.

Ex: – document.cookie = “username=devops; path=/”;

Ex: – document.cookie = “username=devops; path=/home”;

secure

Cookie to only be transmitted over secure protocol as https. Before Chrome 52, this flag could appear with cookies from http domains.

Ex: – document.cookie = “username=devops; secure”;

Tagged : / / / / /

What are the differences between HTML5 and HTML?

What is HTML?

HTML is for hypertext markup language. Browsers do not display HTML tags but are used to render the content of the page. Hypertext is a special method by which we can roam the web by clicking on the hyperlinks that open the next page. Markup HTML tags such as that by which to open the tags with their inside text and off we can format the text, put hyperlinks, images and more. The HTML World Wide work the basic building blocks for the web. HTML was created in 1991 by Tim Berners-Lee, who is also the founder of the World Wide Web.

What is HTML 5

HTML5 was released in 2014. HTML is placed on all over the Internet and updated with more features to make it more accessible. HTML5 is different from HTML, because all its features are supported in all browsers.HTML5 has been recommended by the W3C in 2012. This includes processing models, detailed parsing rules, error handling, canvas for drawing, and support for local storage. HTML5 begins to support geolocation APIs such as JavaScript APIs to identify location, cross-platform mobile application support. HTML5 defines a single markup language that can be written in HTML or XHTML language syntax and supports backward compatibility for the previous version 5.

Differences Between HTML vs HTML5

HTML is an abbreviation for hypertext markup language, a combination of hypertext and Markup.HTML is the backbone of any website because it is a key part of every website’s MAR-end code. The use of HTML markup describes the structure of HTML pages or web pages.HTML5 is the 5th version of the HTML standard that was finalized. HTML5 supports integration of video and audio into the language. HTML5 reduces the need for third-party plugins and deprecated elements.

The most important differences between HTML vs HTML5 are given below:

  • HTML is not supported in video and audio whereas in HTML5, video and audio are integrated into it.
  • HTML is compatible with almost all browsers, while HTML5 is supported by most modern browsers such as Firefox, Mozilla, and Chrome.
  • In HTML5, the tag can have only one attribute range and the value must be zero or one whereas in HTML we can have multiple attributes.
  • HTML is unable to handle incorrect syntax and other errors while HTML5 is capable of handling errors.
  • In HTML the tag was used as an anchor as well as to refer to a link while in HTML5 the tag is used only as a computer.
  • In HTML, the tag was used to display the abbreviation, whereas in HTML5 the tag is replaced by the tag which will be used for the same purpose.

Tagged : / /

Debugging JavaScript with Chrome DevTools Breakpoints

To debug JavaScript in Google Chrome use Developer Tools
To set a breakpoint, simply click on the grey margin where you see line numbers in the Sources tab
Stepping through the code-

Step Over – F10
Step into – F11
Step out Shift+F11
Continue F8

You can also use the following buttons in the Developer tools to step through the code-

To set a conditional breakpoint, right click on the grey margin and select “add conditional breakpoint”

The Call Stack panel displays the complete excetion path and in this path where you want to breakpoint add select any line where auto color blue background that means javascript excution pouse at breakpoint.

If you want to find a individual id then press

Ctrl+shift+I

and go to console tab and select

Ctrl+shift+F

and paste any id and press enter

Tagged : / / / /