Return to Snippet

Revision: 1398
at October 3, 2006 05:39 by mlange


Initial Code
/*
self and window
-> These refer to the global object of current web page.
parent
-> Refers to the window object of the page that is holding the current page in a frameset.
top
-> Refers to the window object of the page at the top of the frames hierarchy.
window.frames[nameOrNumberOfFrame]
-> Refers to a frame or iframe held by the current page.
*/

// -----------------------------
//   frames

window.frames[nameOrNumberOfFrame].window



// -----------------------------
//   breaking out of frame

/*
If someone is loading your page into their frameset and you don't want them to, you can use the self-top relationship to remove your page from their frameset and replace their frameset page with your page using:
*/

if( self != top ) { top.location.replace(self.location.href); }



// -----------------------------
//   hierarchy

parent.frames['otherframename'].document.images['imagename'].src = "sample.gif";



// -----------------------------
//   parent

window.parent.parent.frames['left']
window.top.frames['left']



// -----------------------------
//   forms

reference_to_form.inputname
reference_to_form.elements['inputname']
reference_to_form.elements[number_of_input_(not_image_input)]
document.nameOfForm.mybutton[1]



// -----------------------------
//   selectbox

if( document.myForm.mySelect.selectedIndex == 1 ) {
  document.myForm.mySelect.options[3].selected = true;
  if( !document.myForm.myRadio[1].checked ) {
      document.myForm.myRadio[2].checked = false;
    document.myForm.myRadio[1].checked = true;
    document.myForm.myRadio[0].checked = false;
  }
}



// -----------------------------
//   setting a select option to null will remove 
//   it from the select box

document.forms[number_of_form].mySelect.options[0] = null;



// -----------------------------
//   images

if( document['imagename'].src == "pig.gif" ) {
...
if( document['imagename'].src == myImage.src ) {



// -----------------------------
//   anchors

document.anchors[number_of_<a>_element]
//  if the href attribute is set, you can refer to it using this:
document.links[number_of_<a>_element]

Initial URL
http://www.howtocreate.co.uk/tutorials/javascript/browserinspecific

Initial Description
Source: Browser inspecific referencing @ howtocreate

Initial Title
Referencing window elements

Initial Tags
DOM

Initial Language
JavaScript