Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

malcolmk33's Achievements


Newbie (1/14)



  1. Yes, perhaps what is lacking is access to the complete set of codes (JavaScript and HTML, or even the CSS if there's one) pertinent to the example discussed. I've checked in the downloaded chapter 9 folder, but couldn't find those files. I wonder if you'd be able to embed those codes here. Think it would help me dearly to understand the obfuscated objectives set in the aforementioned section. By the way, really enjoy your book so far.
  2. Hi Larry and fellow forum members, I've so far found this forum to be extremely helpful in finding answers to most questions that arises while I'm reading the book. However, as I've just finished reading chapter 9, I'm having some difficulty in understanding the gist of the sub-section called 'Creating Representative URLs'. So, here are my questions : 1) The following is the first script included in this section: var hash = window.location.hash; // Includes the # var content = hash.charAt(1); // Get the second character switch (content) { case 2: // Show tab 2. break; case 3: // Show tab 3. break; case 1: default: // Show tab 1. break; } Then it's followed by the paragraph that says: 'The actual specifics for how you change the content will be explained later in the chapter '. So, can I assume that there are some missing code that should be added within or after the above code in order to change the content (I wonder what these codes are). But what does he mean anyway- to change the content? I thought this section is meant to show us how to create page bookmarks using the window.location.hash property. 2) Then those were immediately followed by: 'For this to work, the JavaScript also has to update the URL when the page’s state changes. Say the setTab() function is called when the user clicks on a tab and it takes the event as an argument: ' function setTab(e) { if (typeof e == ‘undefined’) var e = window.event; } Is that all to it for declaring the setTab() function? I thought it's supposed to contain some onclick event handling code to be declared within the function. If I'm right, what might the code be like? 3) Next comes the following paragraph and one line of code: 'Using the event’s target or srcElement property (depending upon the browser; see Chapter 8), the function would know which tab to show. If the function gets that information and stores it in the tab variable, the JavaScript can then dynamically change the URL accordingly: ' window.location.hash = ‘#’ + tab; Here, I assume that we have to write some code that declare a function that reference the event target and also create a variable named 'tab' that get its value from referencing some HTML elements. But, what should the tab variable reference to? Perhaps the id of the tab that the user click on (which one must procure through the e.target/e.srcElement property). Again, I assume some additional code must be missing. 4) The section ends with: 'And that’s all there is to it (in theory). The user can bookmark the page and return to it in the same state as it was when the user left. Even if the user were to refresh the page, the state would remain the same. ' I could barely grasp the theory at this point. But what I'm more interested in is: how to put them in practical use. Just how one can 'bookmark the page and return to it in the same state as it was when the user left'. How does the complete script for such an application look like? 5) The end of the chapter return to the discussion of the above topic. It shows how to update the hash value as one uses the Back and Forward buttons to navigate. And, these code are provided: var hash = window.location.hash; var hashWatcher = setInterval(function() { if (window.location.hash != hash) { // Changed! updatePage(); }}, 1000); // Every second. Ok, perhaps this part is not difficult to understand. But, still, the whole chapter didn't address the solution (at least not to my satisfaction) to the question of how to share the specific tab information (i.e., browser state) with another person, as it was brought up at the beginning of the section 'Creating Representative URLs'. As no one has mentioned this part of the book in the forum yet, I wonder if I'm the only one to have overlooked something (up to chapter 9) that might help clearing the uncertainties that I have on this topic. Or, perhaps, by charging on with the rest of the book, I would eventually find the solution written somewhere.
  • Create New...