JavaScript DHTML/HTML/URL

Материал из Web эксперт
Перейти к: навигация, поиск

document.URL Property Reader

   <source lang="html4strict">

<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>


<FORM>

Select a window or frame to view each document property values.

<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>

document.URL: <TEXTAREA NAME="dLoc" ROWS=3 COLS=30 WRAP="soft"></TEXTAREA>
document.title: <TEXTAREA NAME="dTitle" ROWS=3 COLS=30 WRAP="soft"></TEXTAREA>

</FORM> </BODY> </HTML>

      </source>
   
  


Extracting the Directory of the Current Document

   <source lang="html4strict">

<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>


</source>