|
14 | 14 | // Project Home - http://benalman.com/projects/jquery-hashchange-plugin/ |
15 | 15 | // GitHub - http://github.com/cowboy/jquery-hashchange/ |
16 | 16 | // Source - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.js |
17 | | -// (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (1.3kb) |
| 17 | +// (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (0.8kb gzipped) |
18 | 18 | // |
19 | 19 | // About: License |
20 | 20 | // |
|
37 | 37 | // reside (so you can test it yourself). |
38 | 38 | // |
39 | 39 | // jQuery Versions - 1.2.6, 1.3.2, 1.4.1, 1.4.2 |
40 | | -// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.7, Safari 3-5, Chrome 3-5, Opera 9.6-10.5. |
| 40 | +// Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Safari 3-5, Chrome 3-5, Opera 9.6-10.5. |
41 | 41 | // Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/ |
42 | 42 | // |
43 | 43 | // About: Known issues |
|
60 | 60 | // file to address access denied issues when setting document.domain in |
61 | 61 | // IE6/7. Note that when using <jQuery.hashchangeIframeSrc>, history |
62 | 62 | // won't be recorded in IE6/7 until the Iframe src file loads. Lowered |
63 | | -// the default <jQuery.hashchangeDelay> to 50 milliseconds. Attempt to |
64 | | -// make Iframe as hidden as possible by using techniques from |
65 | | -// http://www.paciellogroup.com/blog/?p=604. |
| 63 | +// the default <jQuery.hashchangeDelay> to 50 milliseconds. Added IE6/7 |
| 64 | +// document.title support. Attempt to make Iframe as hidden as possible |
| 65 | +// by using techniques from http://www.paciellogroup.com/blog/?p=604. |
66 | 66 | // 1.2 - (2/11/2010) Fixed a bug where coming back to a page using this plugin |
67 | 67 | // from a page on another domain would cause an error in Safari 4. Also, |
68 | 68 | // IE6/7 Iframe is now inserted after the body (this actually works), |
|
262 | 262 | // Append Iframe after the end of the body to prevent unnecessary |
263 | 263 | // initial page scrolling (yes, this works). |
264 | 264 | .insertAfter( 'body' )[0].contentWindow; |
| 265 | + |
| 266 | + // Whenever `document.title` changes, update the Iframe's title to |
| 267 | + // prettify the back/next history menu entries. Since IE sometimes |
| 268 | + // errors with "Unspecified error" the very first time this is set |
| 269 | + // (yes, very useful) wrap this with a try/catch block. |
| 270 | + document.onpropertychange = function(){ |
| 271 | + try { |
| 272 | + if ( event.propertyName === 'title' ) { |
| 273 | + iframe.document.title = document.title; |
| 274 | + } |
| 275 | + } catch(e) {} |
| 276 | + }; |
| 277 | + |
265 | 278 | } |
266 | 279 | }; |
267 | 280 |
|
|
279 | 292 | // document, *then* setting its location.hash. If document.domain has |
280 | 293 | // been set, update that as well. |
281 | 294 | history_set = function( hash, history_hash ) { |
| 295 | + var doc = iframe.document, |
| 296 | + domain = $[ str_hashchange + 'Domain' ]; |
| 297 | + |
282 | 298 | if ( hash !== history_hash ) { |
283 | | - var doc = iframe.document.open(), |
284 | | - domain = $[ str_hashchange + 'Domain' ]; |
| 299 | + // Update Iframe with any initial `document.title` that might be set. |
| 300 | + doc.title = document.title; |
285 | 301 |
|
| 302 | + // Opening the Iframe's document after it has been closed is what |
| 303 | + // actually adds a history entry. |
| 304 | + doc.open(); |
286 | 305 | domain && doc.write( '<script>document.domain="' + domain + '"</script>' ); |
287 | 306 | doc.close(); |
288 | 307 |
|
| 308 | + // Update the Iframe's hash, for great justice. |
289 | 309 | iframe.location.hash = hash; |
290 | 310 | } |
291 | 311 | }; |
|
0 commit comments