Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

JavaScript Location Object

By Exforsys | on July 4, 2007 |
JavaScript Tutorial

JavaScript Location Object

In this JavaScript tutorial, you will learn about JavaScript Location Object – assign(), reload(), replace(), JavaScript Window Object Methods viz alert(), blur(), setInterval() and clearInterval().

Methods of Location Object

assign():

The assign method of location object is used for loading a new document.

General syntax of assign method of location Object:


location.assign(URL)

for example

 

<html>
   <
head>
      <
script type="text/javascript">
         function test()
         {
          window.location.assign("
http://www.exforsys.com")
         }

      </script>
   <
/head>
 

   <body>
       <input type="button" value="Click Here For Loading New Document" onclick="test()" />

   </body>
</
html>

The output of the above program is a button with message as


Click Here For Loading New Document

When this button is clicked, the site exforsys.com loads as a document.

reload():

This method of location object is used for reloading the current document. The currently displayed page in the window that owns the location object is reloaded. This means that the document that owns the Location object is to be reloaded.

General syntax of reload method of location Object:


location.reload()

for example


<html>
   <
head>
      <
script type="text/javascript">
         function test()
         {
          window.location.reload()

         }

      </script>
   <
/head>
 

   <body>
       <input type="button" value="Click Here For ReLoading page" onclick="test()" />

   </body>
</
html>

The output of the above program is a button with message as


Click Here For ReLoading Page

When this button is clicked, the current document reloads.

replace():

As the name implies, the replace() method of location object replaces the current document with a new one. The current History entry is replaced with the URL specified in the replace method. NOTE: The programmer must know that after the replace method is called he or she cannot go back to the previous URL by using the back button.

General syntax of replace method of location Object:


location.replace(URL)

The URL specified in argument is the new URL.

for example


<html>
   <
head>
      <
script type="text/javascript">
         function exareplace()
         {
         window.location.replace("http://www.exforsys.com")

         }

      </script>
   <
/head>
 

   <body>
       <input type="button" value="Click Here to Replace" onclick="exareplace()" />

   </body>
</
html>

The output of the above program is a button with message as


Click Here to Replace!!!

When this button is clicked, the current document is replaced with http://www.exforsys.com as document.

JavaScript Window Object Methods

In the section detailing the Introduction to JavaScript and DOM objects, this tutorial presented the list of methods used with Window object. These methods of Window objects are repeated below for referral. The syntax and usage of the methods of Window Objects with explanation in detail about each will be described in the next few sections of this tutorial.

The methods of Window Objects are:

  • alert()
  • blur()
  • setInterval()
  • clearInterval()
  • setTimeout()
  • clearTimeout()
  • close()
  • confirm()
  • createPopup()
  • focus()
  • moveBy()
  • moveTo()
  • open()
  • print()
  • prompt()
  • resizeBy()
  • resizeTo()
  • scrollBy()
  • scrollTo()

alert():

By using the alert() method of window object, users can display an alert box with a message displayed in it as specified by the user.
The string passed to the alert method in argument displays an alert dialog box along with an Ok button inside it. NOTE: The alert() method is used to convey a message where the decision from the user is not required.

General Syntax of the alert() method of window object:


alert(message)

An example to understand the usage of alert() method of window object in brief:


<html>
   <
head>
      <
script type="text/javascript">
         function exforsys()
         {
          alert("Welcome!!!")
         }
    </script>
</head>
<body>
   
<input type="button" onclick="exforsys()"
   
value="Example of alert() method of Window Object!!
    Click Here!!!
" />
   </body>
</
html>

The output of the above example is a button with the message:


Example of alert() method of Window Object!! Click Here!!!

When this button is clicked, the alert box is displayed with the message:


Welcome!!!!

and an ok button displays in the alert box.

The string passed to the alert() method mentioned in the function exforsys() is Welcome!!! This is displayed in the alert box with the ok button.

If a user wants to display messages in alert box by having a line break in the next line then, this is achieved by placing a ‘\n’ between messages and concatenating the messages using the symbol +.

An example to understand the above concept:


<html>
   <
head>
      <
script type="text/javascript">
         function exforsys()
         {
          alert("Welcome!!!" + ‘\n’ +"Have a Good Day!!!")
         }
    </script>
</head>
<body>
   
<input type="button" onclick="exforsys()"
   
value="Example of alert() method of Window Object!!
    Click Here!!!
" />
   </body>
</
html>

The output of the above example is a button with the message:


Example of alert() method of Window Object!! Click Here!!!

When this button is clicked, the alert box is displayed with the message:


Welcome!!!
Have a Good Day!!!

And an ok button is displayed in this alert box.

In the above example, the message Have a Good Day!!! is placed after ‘\n‘ and thus is displayed in the next line of the previous Welcome message.

blur():

The blur() method of a Window object removes the focus from the current window. The blur() method of a window object is used to take the focus away from the current window.

General Syntax of the blur() method of window object:


window.blur()

An example to understand the usage of blur() method of window object:


<html>
   <
body>
      <
script type="text/javascript">
         exforsys=window.open(”,”,’width=100,height=100‘)
         exforsys.document.write("
Window is ‘exforsys’")
         exforsys.blur()
     
</script>
 
</body>
</html>

In the above example, the focus is taken away from the current window (the exforsys window). The window named exforsys is opened using the window.open. The focus from the current window (exforsys) is removed using the exforsys.blur() statement.

setInterval():

The setInterval() method of a window object takes two arguments. The first argument is a function or an expression and the second argument is milliseconds. The setInterval() method of a window object is used to call a function or evaluate an expression at specified intervals (in this example, milliseconds). The calling of function or expression is continued until the window is closed or until the clearInterval() method is called. The setInterval() method returns an ID value which is used as a parameter for clearInterval method.

General Syntax of the setInterval() method of window object:


window.setInterval(expression/function, milliseconds)

The expression/function mentioned is evaluated at specified intervals (milliseconds).

clearInterval():

The setInterval() method of a window object is used to call a function or evaluate an expression at specified intervals. The interval set by the setInterval() method of a window object cancels with the clearInterval() method of a window object.

General Syntax of the clearInterval() method of window object:


window.clearInterval(intervalID)

Here, the intervalID mentioned in argument of clearInterval() method represents the ID value returned by the setInterval() method.

« « Service Oriented Architecture : Why SOA?
NLP Strategy Model » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 392 Followers
  • Popular
  • Recent
  • How to use JavaScript in HTML page

    April 20, 2007 - 0 Comment
  • JavaScript Document Object Properties

    June 13, 2007 - 0 Comment
  • JavaScript Arrays

    June 7, 2007 - 0 Comment
  • JavaScript Elements and Embed Objects

    August 4, 2007 - 0 Comment
  • JavaScript Array Object

    June 6, 2007 - 0 Comment
  • JavaScript Conditional Statements Part 1

    April 24, 2007 - 0 Comment
  • JavaScript Document Object Methods Part I

    August 5, 2007 - 0 Comment
  • JavaScript Functions

    June 5, 2007 - 0 Comment
  • JavaScript Event Object

    May 20, 2007 - 0 Comment
  • JavaScript Array Object Methods – Part I

    July 17, 2007 - 0 Comment
  • JavaScript Objects

    August 12, 2007 - 0 Comment
  • JavaScript String Object

    August 12, 2007 - 0 Comment
  • JavaScript Date Object

    August 12, 2007 - 0 Comment
  • JavaScript Math Object

    August 9, 2007 - 0 Comment
  • JavaScript Windows Object Properties Part II

    August 9, 2007 - 0 Comment
  • JavaScript Windows Object Properties Part I

    August 8, 2007 - 0 Comment
  • JavaScript Window Object Timeout Methods

    August 8, 2007 - 0 Comment
  • JavaScript Document Object Methods Part II

    August 7, 2007 - 0 Comment
  • JavaScript Document Object Methods Part I

    August 5, 2007 - 0 Comment
  • JavaScript History Object Properties and Methods

    August 5, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • JavaScript Objects
  • JavaScript String Object
  • JavaScript Date Object
  • JavaScript Math Object
  • JavaScript Windows Object Properties Part II

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT