Click the button to open an about:blank page in a new
browser window that is 200px wide and 100px tall.
‘Scanned with CamScannerJavaScript Program to OPEN NEW Window with website
Click the button to open a new browser window.
‘Scanned with CamScannerNew Window Focus
+ A focus to a new window can be giving using focus()
method.
‘Scanned with CamScanneeJavaScript Program to set new window focus using Focus method
Click the button to open a new window, and assure that the new
window GETS focus
(send the new window to the front).
‘Scanned with CamScannerWindow Position
+ We can set the desired position for the window.
* Using the left and top attribute values the window
position can be set.
* style attribute as left=0, top=0 in open method, the window
is created and positioned at the extreme left and top
location screen
‘Scanned with CamScanneeJavaScript Program to set new window position
Click the button to open a new window with some specifications.
‘Scanned with CamScannerChanging Window Content
¢ By writing some text to the newly created window we can
change the contents of a window
‘Scanned with CamScanneeJavaScript Program to change the content of window
‘Scanned with CamScannerClose Window
* The most simple operation about the window is to close it. It
can be close using the function close().
‘Scanned with CamScanneeJavaScript Program to close the window
‘Scanned with CamScannerScrolling Web Page
+ We can scroll horizontally or vertically using scrollTo()
function.
+ Second Program see on page no.21
‘Scanned with CamScanneeJavaScript Program to Scroll the Web Page.
Click the button to scroll the document window to 500 pixels horizontally.
‘Scanned with CamScannerMultiple Windows at Once
* It is possible to open up multiple windows at a time.
Simply put open() method multiple time
‘Scanned with CamScanneeJavaScript Program to open Multiple Windows at Once.
Click the button to open multiple tabs.
‘Scanned with CamScannerCreating Web Page in New Window
We can create a web page using the window object with the
help of write method.
* The only thing is that inside the write we have to write the
contents of the web page with the help of html element
such as , , ,
and so on.
‘Scanned with CamScanneeJavaScript Program to create web page in new window
‘Scanned with CamScannerJava Script in URLs
The JavaScript code can be included in client side.
¢ JavaScript can be specified in URL using the pseudo-protocol
specifier.
* This special protocol type specifies that the body of the URL
is arbitrary JavaScript code to be interpreted by the
JavaScript interpreter.
For example we can type following code in URL bar
This will show a pop up window of alert box.
If the JavaScript code in a JavaScript: URL contains
multiple statements then these statements must be separated
by semicolons. For example —
But for the security reasons modem web browsers are not
allowing to execute’ JavaScript:" code in URL.
‘Scanned with CamScanneeJavaScript Security
Javascript has several security issues that need widespread attention.
One of the most common JavaScript security vulnerabilities is Cross-Site
Scripting (XSS).
Cross-Site Scripting vulnerabilities enable attackers to manipulate
websites to return malicious scripts to visitors.
This vulnerability may cause the user data theft, account tampering and
so on.
JavaScript vulnerabilities can be both client-side problems and _ server-
side as well as hackers are able to steal server-side data and infect the
users with malware. Therefore, server-side JavaScript injection is also a
much more dangerous problem in an application.
+ Cross-Site Request Forgery (CSRF) attack is another issue in
Javascript Cross-Site
Request Forgery involves taking over or impersonating a user's browser
session by hiiacking the session cookie.
‘Scanned with CamScanneeTimer
Using window object it is possible to execute the code at specified time
intervals.
Two functions are supported by window object for handling timing events
and those are —
1. setTimeout
2. setinterval
(1) setTimeout ()
This method executes function after waiting for a specified number
of milliseconds.
Syntax
[Link](function, milliseconds):
function- function to be executed
milliseconds- no of milliseconds before execution take place
The function is only executed once
‘Scanned with CamScannerJavaScript Program to execute timer with setTimeout Method
‘Scanned with CamScannerTimer Cont..
[Link] setInterval() method calls a function or evaluates an
expression at specified intervals(in milliseconds).
‘Scanned with CamScanneeJavaScript Program to execute timer with setInterval Method
‘Scanned with CamScannerBrowser location and history
(1) Location
The location object contains information about the current URL.
The location object is part of the window object and is accessed through
the window. location property.
‘Scanned with CamScanneeBrowser location and history Cont..
Location Object Properties
Sr. [Property Description
No
1 hash Sets or returns the anchor part (#) of a URL
2 host Sets or returns the hostname and port number of a URL
8 hostname | Sets or returns the hostname of a URL
4 href Sets or returns the entire URL
5 origin Returns the protocol, hostname and port number of a URL
6
pathname Sets or returns the path name of a URL
7 | port
Sets or returns the port number of a URL
‘Scanned with CamScanneeBrowser location and history Cont..
Location Object Properties
[Link] |Property Description
protocol Sets or returns the protocol of a URL
9 search Sets or returns the query string part of a URL
‘Scanned with CamScanneeBrowser location and history Cont..
Location Object Methods
[Link] Methods
Description
1 assign Loads a new document
2 reload Reloads the current document
3 teplace() Replaces the current document with a new one
4 assign
Loads a new document
‘Scanned with CamScanneeJavaScript Program to display the path name of the web page using
[Link] object
‘Scanned with CamScannerJavaScript Program to display the protocol name of the web page using
[Link] object
‘Scanned with CamScannerJavaScript Program to display the URL of current web page using
[Link] object
‘Scanned with CamScannerJavaScript Program to display the Host name of web page using
[Link] object
‘Scanned with CamScannerJavaScript Program to display the Host name of web page using
[Link] object
‘Scanned with CamScannerJavaScript Program to load web page document using
[Link] object
‘Scanned with CamScannerWindow History
The window. history object contains the browsers
history.
There are two methods:
[Link]()
This method load the previous URL in history list.
Same as clicking back in the browser
[Link]()
This method loads the next URL in the history. Same as clicking
forward in the browser
[Link]()
method loads the previous URL in the history list.
This is the same as clicking the Back button in the
browser.
‘Scanned with CamScanneeJavaScript Program to load previous URL of the current web page using
[Link]() method
‘Scanned with CamScannerWindow History Cont..
[Link]()
method loads the next URL in the history list.
This is the same as clicking the Forward button in the
browser.
‘Scanned with CamScanneeJavaScript Program to load next URL of the current web page using
[Link]() method
‘Scanned with CamScannerIK YOU?!