JavaScript DHTML/HTML/URL — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 07:23, 26 мая 2010
document.URL Property Reader
<HTML>
<HEAD>
<TITLE>URL Property Reader</TITLE>
<SCRIPT LANGUAGE="JavaScript1.1">
function fillTopFrame() {
newURL=prompt("Enter the URL of a document to show in the top frame:","")
if (newURL != null && newURL != "") {
top.frames[0].location = newURL
}
}
function showLoc(form,item) {
var windName = item.value
var theRef = windName + ".document"
form.dLoc.value = unescape(eval(theRef + ".URL"))
form.dTitle.value = unescape(eval(theRef + ".title"))
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="button" NAME="opener" VALUE="Open URL..." onClick="fillTopFrame()">
</FORM>
<HR>
<FORM>
Select a window or frame to view each document property values.<P>
<INPUT TYPE="radio" NAME="whichFrame" VALUE="parent" onClick="showLoc(this.form,this)">Parent window
<INPUT TYPE="radio" NAME="whichFrame" VALUE="top.frames[0]" onClick="showLoc(this.form,this)">Upper frame
<INPUT TYPE="radio" NAME="whichFrame" VALUE="top.frames[1]" onClick="showLoc(this.form,this)">This frame<P>
<TABLE BORDER=2>
<TR><TD ALIGN=RIGHT>document.URL:</TD>
<TD><TEXTAREA NAME="dLoc" ROWS=3 COLS=30 WRAP="soft"></TEXTAREA></TD></TR>
<TR><TD ALIGN=RIGHT>document.title:</TD>
<TD><TEXTAREA NAME="dTitle" ROWS=3 COLS=30 WRAP="soft"></TEXTAREA></TD></TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Extracting the Directory of the Current Document
<HTML>
<HEAD>
<TITLE>Extract pathname</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// general purpose function to extract URL of current directory
function getDirPath(URL) {
var result = unescape(URL.substring(0,(URL.lastIndexOf("/")) + 1))
return result
}
// handle button event, passing work onto general purpose function
function showDirPath(URL) {
alert(getDirPath(URL))
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT TYPE="button" VALUE="View directory URL" onClick="showDirPath(window.location.href)">
</FORM>
</BODY>
</HTML>