JavaScript, Part 4 Instructor: Charles Moen CSCI/CINF 4230.

Slides:



Advertisements
Similar presentations
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Advertisements

The Web Warrior Guide to Web Design Technologies
HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
6/10/2015Cookies1 What are Cookies? 6/10/2015Cookies2 How did they do that?
JavaScript Forms Form Validation Cookies CGI Programs.
16-Jun-15 HTTP Hypertext Transfer Protocol. 2 HTTP messages HTTP is the language that web clients and web servers use to talk to each other HTTP is largely.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
How the web works: HTTP and CGI explained
JavaScript ICW: Lecture 11 Tom Chothia. Last Lecture URLs Threads, to make a process run in parallel: Make it extend Thread Give it a run method Call.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Definitions, Definitions, Definitions Lead to Understanding.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Client, Server, HTTP, IP Address, Domain Name. Client-Server Model Client Bob Yahoo Server yahoo.com/finance.html A text file named finance.html.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
Client-Side programming with JavaScript 3
Web technologies and programming cse hypermedia and multimedia technology Fanis Tsandilas April 3, 2007.
Web Hacking 1. Overview Why web HTTP Protocol HTTP Attacks 2.
Introduction to Web Programming Fall 2014/2015 Some slides are based upon Web Technologies course slides, HUJI, 2009 Extended System Programming Laboratory.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
SUNY Polytechnic Institute CS 490 – Web Design, AJAX, jQuery Web Services A web service is a software system that supports interaction (requesting data,
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
HTTP HTML Introduction to web development. elaborate SPARCS 07 Wheel Moodle TA 안병욱 CS101 TA The presenter is 바퀴짱 ? 3 월 신작 ? 밤의 제왕 ? 악명 높은 TA?
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
2: Application Layer1 CS 4244: Internet Software Development Dr. Eli Tilevich.
Sistem Jaringan dan Komunikasi Data #9. DNS The Internet Directory Service  the Domain Name Service (DNS) provides mapping between host name & IP address.
JavaScript, Fourth Edition
IT Engineering Instructor: Rezvan Shiravi
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Chapter 8 Cookies And Security JavaScript, Third Edition.
JavaScript, Part 3 Instructor: Charles Moen CSCI/CINF 4230.
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
Web Spiders Dan Reeves Bill Walsh HDIW EECS February 2000.
XP Tutorial 6 New Perspectives on JavaScript, Comprehensive1 Working with Windows and Frames Enhancing a Web Site with Interactive Windows.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
JavaScript, Part 2 Instructor: Charles Moen CSCI/CINF 4230.
A Little Bit About Cookies Fort Collins, CO Copyright © XTR Systems, LLC A Little Bit About Cookies Instructor: Joseph DiVerdi, Ph.D., M.B.A.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Fall 2000C.Watters1 World Wide Web and E-Commerce Clients & Client Side Processing.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
IS2802 Introduction to Multimedia Applications for Business Lecture 8: JavaScript and Cookies Rob Gleasure
Overview of Servlets and JSP
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Sessions and cookies (part 2) MIS 3501, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/19/2015.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Fiddler and Your Website Robert Boedigheimer. About Me Web developer since 1995 Columnist for aspalliance.com Pluralsight Author 3 rd Degree Black Belt,
File Uploads and Cookies Pat Morin COMP Outline File upload Cookies.
National College of Science & Information Technology.
CSE 154 Lecture 20: Cookies.
HTTP – An overview.
Sessions and cookies (part 2)
IS333D: MULTI-TIER APPLICATION DEVELOPMENT
Cookies and JavaScript
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
CSc 337 Lecture 27: Cookies.
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
CSc 337 Lecture 25: Cookies.
Presentation transcript:

JavaScript, Part 4 Instructor: Charles Moen CSCI/CINF 4230

DHTML (continued)

3 Browser Object Model (BOM)  Objects that we can use to interact with the browser  Each of these objects has properties, methods, and events JavaScript (Underwood, Koch, Ding‏) Window Document History Navigator Location Screen

4 window Object  Represents the entire browser window, everything in it, and every part of it that is accessible to JavaScript  The DOM is contained within the window object  Some properties: closed – returns true or false, based on whether a particular window is closed name – a name that a script can use to refer to a particular window; the main window open in the browser does not have a name by default self – refers to the current window window – refers to the current window  Some methods: alert() confirm() prompt() JavaScript (Underwood, Koch‏)

5 navigator Object  Represents the browser that was used to request the page  Some properties: appName – name of the browser, but not reliable appVersion – version number of the browser, but not meaningful for us cookieEnabled – true or false userAgent – can be used for “browser sniffing”  Examine the properties: JavaScript (Underwood, Koch, Yue‏) function getProperties() { var navProperties; for (var prop in navigator) { navProperties += prop + ": " + navigator[prop] + "\n"; } alert(navProperties); }

6 Popup Window  An extra window that shows additional information, and allows the user to keep the current page open at the same time  Objections to popups Users are often annoyed by popups The default setting of many browsers is to block popups Many users run popup killer programs JavaScript popups don’t work when JavaScript is disabled JavaScript (Koch‏)

7 Opening a Popup Window  Simplest approach is to use the “target” attribute JavaScript (Koch‏) Open new window

8 Opening a Popup Window  Can also be opened by JavaScript JavaScript (Koch‏) function popup(url) { window.open(url,"Popup","height=480,width=640"); } Open a popup

9 open Method  Third argument contains attributes of the window JavaScript (Underwood, Koch‏) window.open(url,"Popup","height=480,width=640"); URL of the content of the new window, or an empty string Name of the new window Attributes height width left – offset from the left in pixels top – offset from the top in pixels resizable – if yes, allows user to resize scrollbars – if yes, adds scrollbars toolbar – if yes, adds navigation toolbar menubar – if yes, adds the menu bar location – if yes, adds the address bar status – if yes, adds the status bar (at bottom) directories – if yes, adds directories toolbar Using the name of the attribute alone sets the value to yes

HTTP

11 HTTP  Hypertext Transfer Protocol Language for communications between the browser and the Web server Uses a TCP connection over the Internet  Steps for HTTP communications The client uses a URL to open a TCP connection with the server The client sends a request to the server at that URL The server sends a response to the client The TCP connection is closed  The standard was developed by the World Wide Web Consortium and the Internet Engineering Task Force (IETF) HTTP (Wikipedia, Yue‏)

12 URL Uniform Resource Locator The address of a document on the Web HTTP (Ding, Spainhour, Schultz)‏ Protocol HTTP is the language for communicating between the browser and server

13 HTTP Request  There are eight request methods GET – user data is put in the query string of the URL POST – user data is put in the message body of the request HEAD – retrieve only the header, not the body of the response PUT – upload a resource DELETE – delete a resource TRACE – echoes the request for troubleshooting OPTIONS – returns the methods supported by a particular server CONNECT – used with secure https connections HTTP (Wikipedia, Yue‏)

14 HTTP Request HTTP (Spainhour, W3Schools) When the user submits a form, the browser sends an HTTP request over the Internet to a server, and this request passes the value of every control in the form The server sends an HTTP response to the browser containing HTML text GET /moen/welcome.aspx?name=Charles+Moen&location=UHCL HTTP/1.0 This is what the server “sees” in the request The browser may also append header information, such as: Host: dcm.uhcl.edu User-Agent: Mozilla/ Referer:

15 HTTP is Stateless  The server does not “remember” anything about previous requests  For any particular request, the user could be someone entirely new or it could be a repeat visitor who has been sending a request every few minutes, but with HTTP, the server has no way to know. HTTP (Koch, Yue‏)

16 HTTP Request Parts 1.Request header Method field, resource identifier, and HTTP version on the first line Fields, such as the accept fields with information about the client 2.A blank line 3.The message body (for POST requests) HTTP (Yue, Spainhour)‏ GET /moen/welcome.aspx?name=Charles+Moen&location=UHCL HTTP/1.0 Host: dcm.uhcl.edu User-Agent: Mozilla/5.0 [shortened to save space on this slide] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO ,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: GET /moen/welcome.aspx?name=Charles+Moen&location=UHCL HTTP/1.0 Host: dcm.uhcl.edu User-Agent: Mozilla/5.0 [shortened to save space on this slide] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO ,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: Method field HTTP version Resource identifier Fields with information about the client [ a blank line here ]

17 HTTP GET Request and Parameters  method="get"  The name of every form control and its value is appended to the URL of the form handler as part of the query string  The form handler on the server can read and process the values of these query string parameters HTTP (W3Schools, Schultz)‏ URL of the form handler Question mark follows the URL GET /createOrder.aspx?quantity=1&meat=Ham&cheese=yes&lettuce=on&tomato=on&price=4.99 HTTP/1.0 Query string Ampersands separate the name-value pairs quantity=1 Name of the control Value entered by user (visible in the navigation field of the browser)

HTTP POST Request and Parameters  method="post"  The name of every form control and its value is placed in the body of the request  The form handler on the server can read and process the values of these parameters in the body of the request  The name-value pairs are not visible in the navigation field of the browser HTTP (Spainhour, Schultz)‏ URL of the form handler POST /createOrder.aspx HTTP/1.0 User-Agent: Mozilla/2.02Gold (WinNT; I) Accept: image/gif, image/x-xbitmap, image/jpeg, */* Host: Content-type: application/x-www-form-urlencoded Content-length: 62 quantity=1&meat=Ham&cheese=yes&lettuce=on&tomato=on&price=4.99 POST /createOrder.aspx HTTP/1.0 User-Agent: Mozilla/2.02Gold (WinNT; I) Accept: image/gif, image/x-xbitmap, image/jpeg, */* Host: Content-type: application/x-www-form-urlencoded Content-length: 62 quantity=1&meat=Ham&cheese=yes&lettuce=on&tomato=on&price=4.99 Header fields 18 Body section

19 HTTP GET Request and Parameters  A GET request can be created without using a form HTTP Order one ham sandwich

20 HTTP Response HTTP (Spainhour, W3Schools) When the user submits a form, the browser sends an HTTP request over the Internet to a server, and this request passes the value of every control in the form The server sends an HTTP response to the browser containing HTML text HTTP/1.x 200 OK Cache-Control: private Date: Mon, 27 Oct :03:49 GMT Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: Content-Encoding: gzip Vary: Accept-Encoding Transfer-Encoding: chunked Welcome HTTP/1.x 200 OK Cache-Control: private Date: Mon, 27 Oct :03:49 GMT Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: Content-Encoding: gzip Vary: Accept-Encoding Transfer-Encoding: chunked Welcome This is what the browser “sees” in the response

21 HTTP Response Parts 1.Response header HTTP version, status code, and explanation on the first line Fields with information about the server 2.A blank line 3.The response body (the HTML) HTTP (Yue, Spainhour)‏ Status code Response body Fields with information about the server and response A blank line here HTTP/1.x 200 OK Cache-Control: private Date: Mon, 27 Oct :03:49 GMT Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: Content-Encoding: gzip Vary: Accept-Encoding Transfer-Encoding: chunked Welcome

22 HTTP Response Status Codes  General meanings 200 – 299 Success 300 – 399 Redirection to another location or URL hasn’t changed 400 – 599 Errors HTTP (Wikipedia, Yue‏) CodeMeaning 400Wrong request syntax 401Authorization required 402No Chargeto field on a request for a paid service 403Forbidden resource 404The server cannot find the URL requested 405Accessing the resource using a method not allowed 500The server has encountered an internal error and cannot continue with the request 501The server does not support the method of a legal request 502Secondary server does not return a valid response 503The service is unavailable because the server is too busy

Cookies

24 Cookie  A small text file used to keep track of users Either created by JavaScript or sent in the HTTP response Stored on the user’s computer Automatically sent back to the same server in the HTTP request until the cookie expires Contains name-value pairs Programs can store information and retrieve it later Cookies are not viruses or spam or executable programs  Invented by Netscape Cookies (Koch, Wikipedia‏)

25 Why do we use cookies?  Because HTTP is stateless, we use cookies to keep track of the user  Some typical uses Storing user preferences Storing login information Storing shopping cart information Tracking usage statistics Cookies (Koch‏)

26 What is stored in a cookie?  Some browsers, e.g. FireFox, can show you the content of all your cookies In Firefox: Tools > Options... > Privacy > Show Cookies...  A cookie stores name-value pairs The first pair sets the cookie name and its content, such as: mycookie=Charles; expires – if not set, the cookie expires when the browser is closed expires=Tue, 27 Oct :57:40 UTC; path – by default, the directory of the page that set the cookie; to set to all pages on your site, use path=/; domain – the domain of the page that set the cookie domain=uhcl.edu; Cookies (Koch‏)

27 What is wrong with cookies?  Some users disable or delete cookies  They are not portable They are stored on one particular computer Different browsers do not share cookies  Privacy can be compromised by third-party cookies A page may contain images or ads from another domain; the cookies that they set are called third-party cookies, because they belong to a domain that’s different from the rest of the page Advertisers can use cookies to track a particular user across multiple web sites and build a profile of that user Cookies (Koch, Wikipedia‏)

28 Setting a cookie with JavaScript Cookies (Koch, W3Schools‏) function setCookie(cookiename,value,expiredays) { var expdate=new Date(); expdate.setDate(expdate.getDate() + expiredays); document.cookie = cookiename + "=" + escape(value) + ";expires=" + expdate.toGMTString(); } function getCookies() { var myCookies = ""; var cookies = document.cookie.split(";"); for (var i=0; i<cookies.length; i++) { myCookies += cookies[i] + "\n"; } alert(myCookies); } function setCookie(cookiename,value,expiredays) { var expdate=new Date(); expdate.setDate(expdate.getDate() + expiredays); document.cookie = cookiename + "=" + escape(value) + ";expires=" + expdate.toGMTString(); } function getCookies() { var myCookies = ""; var cookies = document.cookie.split(";"); for (var i=0; i<cookies.length; i++) { myCookies += cookies[i] + "\n"; } alert(myCookies); } Set a cookie Set a cookie

29 Sending a cookie from the Server  Cookies are set in the header fields Cookies (Koch, Wikipedia‏) Set-Cookie: cart_content=415DF4591; path=/ In a response Cookie: cart_content=415DF4591; In the next request

30 References Ding, Wei, “JavaScript” UHCL lecture slides, Keith, Jeremy. DOM Scripting: Web Design with JavaScript and the Document Object Model. friends of ED, Koch, Peter-Paul, PPK on JavaScript. New Riders, Schultz, David and Craig Cook, Beginning HTML with CSS and XHTML: Modern Guide and Reference. Apress, W3Schools Online Web Tutorials. “JavaScript Tutorial”. [Online]. Available: Underwood, Lee, “The JavaScript Diaries”. [Online]. Available: Yue, Kwok-Bun, “An Introduction to JavaScript” UHCL lecture notes, 2000.