Skip to content

Commit 8da2c03

Browse files
committed
Added IE6/7 document.title support. Closes cowboy#11.
1 parent 400b357 commit 8da2c03

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

README.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ reside (so you can test it yourself).
2727
1.2.6, 1.3.2, 1.4.1, 1.4.2
2828

2929
### Browsers Tested ###
30-
Internet Explorer 6-8, Firefox 2-3.7, Safari 3-5, Chrome 3-5, Opera 9.6-10.5.
30+
Internet Explorer 6-8, Firefox 2-4, Safari 3-5, Chrome 3-5, Opera 9.6-10.5.
3131

3232
### Unit Tests ###
3333
[http://benalman.com/code/projects/jquery-hashchange/unit/](http://benalman.com/code/projects/jquery-hashchange/unit/)
@@ -57,7 +57,7 @@ Safari: Back Button from a different domain
5757

5858
## Release History ##
5959

60-
1.3pre - (7/5/2010) Reorganized IE6/7 Iframe code to make it more removable (for mobile dev) and added support for document.domain in IE6/7 via jQuery.hashchangeDomain and jQuery.hashchangeIframeSrc properties. Note that when using jQuery.hashchangeIframeSrc, history won't be recorded in IE6/7 until the Iframe src file loads. Lowered the default jQuery.hashchangeDelay to 50 milliseconds.
60+
1.3pre - (7/5/2010) Reorganized IE6/7 Iframe code to make it more "removable" for mobile development. Added jQuery.hashchangeDomain, jQuery.hashchangeIframeSrc properties and document-domain.html file to address access denied issues when setting document.domain in IE6/7. Note that when using jQuery.hashchangeIframeSrc, history won't be recorded in IE6/7 until the Iframe src file loads. Lowered the default jQuery.hashchangeDelay to 50 milliseconds. Added IE6/7 document.title support. Attempt to make Iframe as hidden as possible by using techniques from http://www.paciellogroup.com/blog/?p=604.
6161
1.2 - (2/11/2010) Fixed a bug where coming back to a page using this plugin from a page on another domain would cause an error in Safari 4. Also, IE6/7 Iframe is now inserted after the body (this actually works), which prevents the page from scrolling when the event is first bound. Event can also now be bound before DOM ready, but it won't be usable before then in IE6/7.
6262
1.1 - (1/21/2010) Incorporated document.documentMode test to fix IE8 bug where browser version is incorrectly reported as 8.0, despite inclusion of the X-UA-Compatible IE=EmulateIE7 meta tag.
6363
1.0 - (1/9/2010) Initial Release. Broke out the jQuery BBQ event.special window.onhashchange functionality into a separate plugin for users who want just the basic event & back button support, without all the extra awesomeness that BBQ provides. This plugin will be included as part of jQuery BBQ, but also be available separately.

docs/files/jquery-ba-hashchange-js.html

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/nd/Data/FileInfo.nd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
1.4
22
JavaScript
3-
/srv/projects/jquery-hashchange/jquery.ba-hashchange.js 1278344463 1 jQuery hashchange event
4-
/srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js 1278344669 0 /srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js
3+
/srv/projects/jquery-hashchange/jquery.ba-hashchange.js 1278369175 1 jQuery hashchange event
4+
/srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js 1278369180 0 /srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js

examples/document_domain/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
$(window).bind( 'hashchange', function(){
2626
var hash = location.hash;
2727

28+
// Set the page title based on the hash.
29+
document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
30+
2831
// Iterate over all nav links, setting the "selected" class as-appropriate.
2932
$('#nav a').each(function(){
3033
var that = $(this);

examples/hashchange/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
$(window).bind( 'hashchange', function(){
2020
var hash = location.hash;
2121

22+
// Set the page title based on the hash.
23+
document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
24+
2225
// Iterate over all nav links, setting the "selected" class as-appropriate.
2326
$('#nav a').each(function(){
2427
var that = $(this);

jquery.ba-hashchange.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Project Home - http://benalman.com/projects/jquery-hashchange-plugin/
1515
// GitHub - http://github.com/cowboy/jquery-hashchange/
1616
// 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)
1818
//
1919
// About: License
2020
//
@@ -37,7 +37,7 @@
3737
// reside (so you can test it yourself).
3838
//
3939
// 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.
4141
// Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/
4242
//
4343
// About: Known issues
@@ -60,9 +60,9 @@
6060
// file to address access denied issues when setting document.domain in
6161
// IE6/7. Note that when using <jQuery.hashchangeIframeSrc>, history
6262
// 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.
6666
// 1.2 - (2/11/2010) Fixed a bug where coming back to a page using this plugin
6767
// from a page on another domain would cause an error in Safari 4. Also,
6868
// IE6/7 Iframe is now inserted after the body (this actually works),
@@ -262,6 +262,19 @@
262262
// Append Iframe after the end of the body to prevent unnecessary
263263
// initial page scrolling (yes, this works).
264264
.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+
265278
}
266279
};
267280

@@ -279,13 +292,20 @@
279292
// document, *then* setting its location.hash. If document.domain has
280293
// been set, update that as well.
281294
history_set = function( hash, history_hash ) {
295+
var doc = iframe.document,
296+
domain = $[ str_hashchange + 'Domain' ];
297+
282298
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;
285301

302+
// Opening the Iframe's document after it has been closed is what
303+
// actually adds a history entry.
304+
doc.open();
286305
domain && doc.write( '<script>document.domain="' + domain + '"</script>' );
287306
doc.close();
288307

308+
// Update the Iframe's hash, for great justice.
289309
iframe.location.hash = hash;
290310
}
291311
};

jquery.ba-hashchange.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)