JavaScript DHTML/Window Browser/Location
Содержание
A Document with Anchors
<html>
<head>
<title>location.hash Property</title>
<script type="text/javascript">
function goNextAnchor(where) {
window.location.hash = where;
}
</script>
</head>
<body>
<a id="start" name="start">Top</a>
<input type="button" name="next" value="NEXT" onclick="goNextAnchor("sec3")" />
<a id="sec3" name="sec3">Section 3</a>
<input type="button" name="next" value="BACK TO TOP" onclick="goNextAnchor("start")" />
</body>
</html>
Extracting the Directory of the Current Document
<html>
<head>
<title>Extract pathname</title>
<script type="text/javascript">
function getDirPath(URL) {
var result = unescape(URL.substring(0,(URL.lastIndexOf("/")) + 1));
return result;
}
function showDirPath(URL) {
alert(getDirPath(URL));
}
</script>
</head>
<body>
<form>
<input type="button" value="URL" onclick="showDirPath(window.location.href)" />
</form>
</body>
</html>
Jump to a new location
<HTML>
<BODY>
<SCRIPT>
var password = "";
password="your";
if (password != null) {
location.href= password + ".html";
}
</SCRIPT>
</BODY>
</HTML>
Location property
<SCRIPT LANGUAGE="JavaScript">
var isNav4 = (navigator.appName == "Netscape" &&
parseInt(navigator.appVersion) == 4)
if (top.location.href == window.location.href) {
if (isNav4) {
if (window.innerWidth != 0) {
top.location.href = "http://www.wbex.ru"
}
} else {
top.location.href = "http://www.wbex.ru"
}
}
</SCRIPT>
Methods and Properties of the Location Object
/*
+------------+----------------+------------------------------------------+
Type Item Description
+------------+----------------+------------------------------------------+
Method
+------------+----------------+------------------------------------------+
reload() Reloads the current URL in the browser window.
+------------+----------------+------------------------------------------+
replace() Loads the new page passed in the current browser.
+------------+----------------+------------------------------------------+
Property
+------------+----------------+------------------------------------------+
hash Represents an anchor name in the URL that begins
with the # character.
+------------+----------------+------------------------------------------+
host Represents the hostname and port number of the URL.
+------------+----------------+------------------------------------------+
hostname Represents the hostname part of the URL.
+------------+----------------+------------------------------------------+
href Represents the complete URL.
+------------+----------------+------------------------------------------+
pathname Represents the PATH_INFO part of the URL.
+------------+----------------+------------------------------------------+
port Represents the port part of the URL.
+------------+----------------+------------------------------------------+
protocol Represents the protocol part of the URL.
+------------+----------------+------------------------------------------+
search The search part of the URL, including the ?.
+------------+----------------+------------------------------------------+
*/