Jump to content
Larry Ullman's Book Forums

Pursue Chpt 9 #12


Recommended Posts

Chapter 9 #12 asks the reader to complete the go back link functionality so that it's accomplished in a progressively enhanced manner, similar to how the print functionality was created. I have spent about an hour and a half trying to figure out what this question is asking me to do.

 

I believe the book is referencing the go back link on pg 327. Here is the code mentioned (I added return false; because what was in the book didn't work):

 

<body>
Please <a href="actualpage.html" id="backLink">go back</a>
<script type="text/javascript">
document.getElementById('backLink').onclick = function(){
window.history.back();
return false;
}
</script>
</body>

 

The print button is added to the page only if the print functionality exists. Since the go back function works in all browsers I don't see any connection with the print functionality and the back link. Perhaps there is another way the print button is progressively enhanced? Any insight would be very much appreciated. Thanks!

Link to comment
Share on other sites

As usual, I am attempting to answer your question at work, so I don't have the book handy, but here's my guess at what Larry was going for:

 

Similar to what you said, I think adding a "return false" statement is the key. The idea is that if JS is supported, then you need to return false to suppress the default behavior of the browser when a link is clicked on. However, if JS isn't supported, then the link will function like a standard link should.

 

As such, without knowing more, I would assume that you're on the right track. If you're still having trouble with this, I can confirm things with the book tonight.

 

Also, I don't think there is any connection with the print functionality and the back button. I think the idea of the JS back button is that you can quickly reload the previous page using JS without having to perform an actual page transition (which is less smooth and more time-consuming). However, when JS isn't supported, then the link will function like a standard link and make the necessary page transition without using JS.

  • Upvote 1
Link to comment
Share on other sites

What you're saying all seems right to me except that the question specifically says "complete the go back link functionality so that it's accomplished in a progressively enhanced manner, similar to how the print functionality was created." I can't find the connection between the two. And the back button is created in a progressively enhanced manor having a fallback if Javascript is disabled.

 

If this one is a tricky one for you to don't worry about it. I'm going to skip this one. I'm sure I'll have another question soon enough, Thanks!

Link to comment
Share on other sites

I decided it was time to stop firing blind and actually whip out the book.

Looking at the question you're referring to, Larry is most likely referring to the code on page 333. Specifically:

 

if (typeof window.print == 'function')

 

In other words, if the window.print method is supported, use it. Otherwise, don't. This is what Larry means by progressive enhancement.

Given that, you should probably do something similar to implement the JS back button.

Link to comment
Share on other sites

 Share

×
×
  • Create New...