Permalink
Browse files

Added IE6/7 document.title support. Closes #11.

  • Loading branch information...
1 parent 400b357 commit 8da2c03db054c1c0b8f1e67cc890fe12a8ee015a @cowboy committed Jul 5, 2010
View
@@ -27,7 +27,7 @@ reside (so you can test it yourself).
1.2.6, 1.3.2, 1.4.1, 1.4.2
### Browsers Tested ###
-Internet Explorer 6-8, Firefox 2-3.7, Safari 3-5, Chrome 3-5, Opera 9.6-10.5.
+Internet Explorer 6-8, Firefox 2-4, Safari 3-5, Chrome 3-5, Opera 9.6-10.5.
### Unit Tests ###
[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
## Release History ##
-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.
+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.
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.
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.
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.

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,4 +1,4 @@
1.4
JavaScript
-/srv/projects/jquery-hashchange/jquery.ba-hashchange.js 1278344463 1 jQuery hashchange event
-/srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js 1278344669 0 /srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js
+/srv/projects/jquery-hashchange/jquery.ba-hashchange.js 1278369175 1 jQuery hashchange event
+/srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js 1278369180 0 /srv/projects/jquery-hashchange/jquery.ba-hashchange.min.js
@@ -25,6 +25,9 @@
$(window).bind( 'hashchange', function(){
var hash = location.hash;
+ // Set the page title based on the hash.
+ document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
+
// Iterate over all nav links, setting the "selected" class as-appropriate.
$('#nav a').each(function(){
var that = $(this);
@@ -19,6 +19,9 @@
$(window).bind( 'hashchange', function(){
var hash = location.hash;
+ // Set the page title based on the hash.
+ document.title = 'The hash is ' + ( hash.replace( /^#/, '' ) || 'blank' ) + '.';
+
// Iterate over all nav links, setting the "selected" class as-appropriate.
$('#nav a').each(function(){
var that = $(this);
View
@@ -14,7 +14,7 @@
// Project Home - http://benalman.com/projects/jquery-hashchange-plugin/
// GitHub - http://github.com/cowboy/jquery-hashchange/
// Source - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.js
-// (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (1.3kb)
+// (Minified) - http://github.com/cowboy/jquery-hashchange/raw/master/jquery.ba-hashchange.min.js (0.8kb gzipped)
//
// About: License
//
@@ -37,7 +37,7 @@
// reside (so you can test it yourself).
//
// jQuery Versions - 1.2.6, 1.3.2, 1.4.1, 1.4.2
-// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.7, Safari 3-5, Chrome 3-5, Opera 9.6-10.5.
+// Browsers Tested - Internet Explorer 6-8, Firefox 2-4, Safari 3-5, Chrome 3-5, Opera 9.6-10.5.
// Unit Tests - http://benalman.com/code/projects/jquery-hashchange/unit/
//
// About: Known issues
@@ -60,9 +60,9 @@
// 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. Attempt to
-// make Iframe as hidden as possible by using techniques from
-// http://www.paciellogroup.com/blog/?p=604.
+// 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.
// 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),
@@ -262,6 +262,19 @@
// Append Iframe after the end of the body to prevent unnecessary
// initial page scrolling (yes, this works).
.insertAfter( 'body' )[0].contentWindow;
+
+ // Whenever `document.title` changes, update the Iframe's title to
+ // prettify the back/next history menu entries. Since IE sometimes
+ // errors with "Unspecified error" the very first time this is set
+ // (yes, very useful) wrap this with a try/catch block.
+ document.onpropertychange = function(){
+ try {
+ if ( event.propertyName === 'title' ) {
+ iframe.document.title = document.title;
+ }
+ } catch(e) {}
+ };
+
}
};
@@ -279,13 +292,20 @@
// document, *then* setting its location.hash. If document.domain has
// been set, update that as well.
history_set = function( hash, history_hash ) {
+ var doc = iframe.document,
+ domain = $[ str_hashchange + 'Domain' ];
+
if ( hash !== history_hash ) {
- var doc = iframe.document.open(),
- domain = $[ str_hashchange + 'Domain' ];
+ // Update Iframe with any initial `document.title` that might be set.
+ doc.title = document.title;
+ // Opening the Iframe's document after it has been closed is what
+ // actually adds a history entry.
+ doc.open();
domain && doc.write( '<script>document.domain="' + domain + '"</script>' );
doc.close();
+ // Update the Iframe's hash, for great justice.
iframe.location.hash = hash;
}
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 8da2c03

Please sign in to comment.