Javascript Course


The location object is part of the window object (but also of the document object), and provides access to the current URL and its components. It can be accessed through the window.location property (or document.location).

window.location (or document.location ) returns the full URL address. But if you assign it a value (a string with a URL address) will load the page from that URL (makes redirect to that address).

- Example, it displays the full address of the page, and after five seconds it redirects to another address (in iframe if the script is into an <iframe>).
document.write('<p>Current address:<br>'+window.location+'<br><br>- After 5 seconds redirects to: //gamv.eu</p>');
window.setTimeout(()=>{window.location ='//gamv.eu';}, 5000);
This object has properties and methods that can be called with the syntax:
window.location.property_name
window.location.methodName()

Properties of the location object


Methods of the location object

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which meta tag provides a short description of the page?
<meta content="..."> <meta description="..."> <meta http-equiv="...">
<meta name="description" content="70-160 characters that describes the content of the page" />
Which CSS property is used to stop the wrapping effect of the "float"?
clear text-align position
#some_id {
  clear: both;
}
Click on the method which gets an array with all the elements in the document that have a specified tag name.
getElementsByName() getElementById() getElementsByTagName()
var divs = document.getElementsByTagName("div");
var nr_divs = divs.length;
alert(nr_divs);
Indicate the PHP function which returns the number of elements in array.
is_[) count() strlen()
$arr =[7, 8, "abc", 10);
$nri = count($arr);
echo $nri;        // 4
The location object

Last accessed pages

  1. String Object (667)
  2. Register and show online users and visitors (39428)
  3. PhpSpreadsheet - Read, Write Excel and LibreOffice Calc files (26057)
  4. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (137889)
  5. Adding text with ActionScript 3 (5501)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (202)
  2. Read Excel file data in PHP - PhpExcelReader (66)
  3. The Mastery of Love (56)
  4. PHP Unzipper - Extract Zip, Rar Archives (51)
  5. Working with MySQL Database (34)
Chat
Chat or leave a message for the other users
Full screenInchide