JavaScript Base Methods        Methods are actions or functions that an object

JavaScript Base Methods        Methods are actions or functions that an object do, or they’re done on an object.
Generic placeholder image

Mukesh R

JavaScript Base Methods

       Methods are actions or functions that an object do, or they’re done on an object. Closing or opening a window, writing a text and etc. are some examples. To access to a method put a dot after an object name and then write the method name (like properties); after that open a parenthesis (like 'alert' function) and insert input data (if they exist); finally close the parenthesis.
 
'document' object has some useful methods listed below:
 
Method
Description
Example
.write (sText)
Write a String Text with HTML format at the first of the page
document.write ('<br>salam')
.execCommand (cmdID)
Does a command like saving as or refreshing the page.
document.execCommand ('Print')
document.execCommand ('SaveAs')
 
And the 'window' object methods:
 
Method
Description
Example
.alert ([message])
'alert' function. The message is optional.
window.alert ('Hellow')
.blur()
Hides the window.
window.blur ()
.close ()
Closes the window after asking a question.
window.close ()
.confirm ([message])
A Message Box with OK-Cancel buttons.
window.confirm ('The window is Restarted.')
.moveTo (x,y)
Moves the window to the specified position
window.moveTo (80,80)
.moveBy (x,y)
Moves the window base on the current position
window.moveBy (90,90)
.navigate (url)
Opens the url (Address) in the page (go
window.navigate ('http://www.javascriptfreecode.com')
.open ([url])
Opens a new page (Blank if no url is specified)
window.open ('http://www.javascriptfreecode.com')
.prompt([message], [defstr])
Opens A box to ask a message (optional) with an initial optional value 'defstr'
window.prompt ('Your Age?', 22)
.resizeTo (x,y)
Resize the window to defined size (x=width, y=height)
window.resizeTo (800,500)
.resizeBy (x,y)
Add x to the current width and y to the current height of the page.
window.resizeBy (-80,220)
.setTimeout (expression, msec)
Does an expression (JavaScript code here) cyclically after an interval (millisecond period)
window.setTimeout ("alert ('salam')" ,3000)
.setInterval (expression, msec)
Does an expression one time after an interval (millisecond period)
window.setInterval ("alert ('salam')" ,3000)
 
    At the last two rows, the expressions should be written in the quotes; we’ve written it in the double quotes because the expression itself has a string value (alert message) that must be in another quote; infact we’ve done it to prevent malfunctions.
 
    Remember that the 'window object name can be removed from above codes and you can use them directly.
Note that some methods may not be supported by some browsers. They may not work properly or at all in them.