Online Documentation Server
 ПОИСК
ods.com.ua Web
 КАТЕГОРИИ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ПОДПИСКА

 О КОПИРАЙТАХ
Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.




Previous Table of Contents Next

bodyDefinition()

// returns <BODY> tag
// (excluding ">" and "<") reflecting all selections
function bodyDefinition() {
 var str = 'BODY '
 str += 'BGCOLOR="#' + bgcolor.r + bgcolor.g + bgcolor.b + '" '
 str += 'LINK="#' + link.r + link.g + link.b + '" '
 str += 'ALINK="#' + alink.r + alink.g + alink.b + '" '
 str += 'VLINK="#' + vlink.r + vlink.g + vlink.b + '" '
 str += 'TEXT="#' + text.r + text.g + text.b + '"'
 return str
}

The bodyDefinition() function constructs and returns a complete <BODY> tag, based on the current values of the descriptors of each attribute. For instance, the function might return the following string:

BODY BGCOLOR="#FFFFCC" LINK="#FF00CC" ALINK="#00FF99" VLINK="#006633"
TEXT="#0000FF"

Notice that we do not include the less than (“<”) and greater than (“>”) characters in the final string.

update()

// update main window
function update() {
 var bodyDef = bodyDefinition()
 var result = ""
 result += '<HTML><HEAD><TITLE>Main</TITLE></HEAD>'
 result += '<' + bodyDef + '>'
 result += '<CENTER>'
 result += 'Text<B>Text</B><HR WIDTH=50%>'
 result += '<FONT COLOR="#' + link.r + link.g + link.b + '">
Link<B>Link</B><HR WIDTH=50%></FONT>'
 result += '<FONT COLOR="#' + alink.r + alink.g + alink.b + '">
Alink<B>Alink</B><HR WIDTH=50%></FONT>'
 result += '<FONT COLOR="#' + vlink.r + vlink.g + vlink.b + '">
Vlink<B>Vlink</B><HR WIDTH=50%></FONT>'
 result += '<BR><FONT SIZE=2><' + bodyDef + '></FONT>'
 result += '</CENTER></BODY></HTML>'

  // assign document object of main frame to local variable
 var doc = frames[2].document

 // close data stream to document
 doc.close()

 // open new data stream to document (text/html)
 doc.open('text/html')

 // print HTML content
 doc.write(result)

 // close data stream to document
 doc.close()
}

The update() function generates the HTML content of the main frame (the right one). The first portion of the function simply assigns the new HTML document to the local variable result. We then assign the document object of that frame window to the local variable doc. In order to replace the old HTML content with the newly generated one, we close the current data stream to the right frame document and reopen a new one to it. Since there is no apparent reason for the current data stream to be open, its closing is optional, and is done here just to be on the safe side. Forgetting to reopen the data stream, though, will crash the browser under certain situations. Since we are printing ASCII text with HTML formatting, we specify the MIME type as text/html, which is also the default MIME value. After printing the entire HTML content to the frame’s document via the write() method, we close the data stream. Note that it is very important to open a stream before printing to a document, and to close the stream afterwards. The close() method displays text or images that were previously sent to layout.

save()

// stores all selections as a cookie
function save() {
 var slot = link.r + link.g + link.b +
alink.r + alink.g + alink.b +
vlink.r + vlink.g + vlink.b +
text.r + text.g + text.b +
bgcolor.r + bgcolor.g + bgcolor.b
 var now = new Date()
 fixDate(now)
 now.setTime(now.getTime() + 31 * 24 * 60 * 60 * 1000) // one month
 setCookie("slot", slot, now)
}

This function combines the descriptors of all attributes to one string and stores it as a cookie, set to expire one month later. Since the load() function relies on the order in which the descriptors are concatenated, the order cannot be altered.

load()

// load values from cookie (concatenation order in save() matters!)
function load() {
 var slot = getCookie("slot")
 if (slot != null) {
  link.r = slot.substring(0, 2)
  link.g = slot.substring(2, 4)
  link.b = slot.substring(4, 6)
  alink.r = slot.substring(6, 8)
  alink.g = slot.substring(8, 10)
  alink.b = slot.substring(10, 12)
  vlink.r = slot.substring(12, 14)
  vlink.g = slot.substring(14, 16)
  vlink.b = slot.substring(16, 18)
  text.r = slot.substring(18, 20)
  text.g = slot.substring(20, 22)
  text.b = slot.substring(22, 24)
  bgcolor.r = slot.substring(24, 26)
  bgcolor.g = slot.substring(26, 28)
  bgcolor.b = slot.substring(28, 30)
  eval(curAttribute()).display()
  update()
 }
}

The load() function retrieves the descriptors for each attribute stored in the cookie. If the cookie does not exist (the user did not press “Save” within the last month), the function is terminated. Otherwise the function extracts each descriptor from the string and assigns it to the corresponding property. The function then displays the new values in the upper frame and updates the main frame accordingly.

Previous Table of Contents Next


With any suggestions or questions please feel free to contact us