jquery/jquery-mobile — Issue #3677: thisUrl is undefined Line 2998 of jquery.mobile-1.1.0-rc.1.js
Author: dcarrith
Created: 2012-02-29 15:57:38+00:00
State: open

This seems to be an issue in every browser I've tested in. Granted, I have not tested in IE which seems to be the browser that at least part of the code is tailored to.

Here's the issue. I have a simple page that lists users and I'm getting the following error when I click on one of the user li elements that should load the user details page:

thisUrl is undefined
http://www.mydomain.com/includes/js/jquery.mobile-1.1.0-rc.1.js
Line 2998

So, I looked at line 2998 and this seems to be the problematic section of code in jquery.mobile-1.1.0-rc.1.js:

2987 //rewrite src and href attrs to use a base url
2988 if( !$.support.dynamicBaseTag ) {
2989	var newPath = path.get( fileUrl );
2990	page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
2991	var thisAttr = $( this ).is( '[href]' ) ? 'href' :
2992	$(this).is('[src]') ? 'src' : 'action',
2993	thisUrl = $( this ).attr( thisAttr );
2994
2995	// XXX_jblas: We need to fix this so that it removes the document
2996	// base URL, and then prepends with the new page URL.
2997	//if full path exists and is same, chop it - helps IE out
2998	thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
2999
3000	if( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
3001	$( this ).attr( thisAttr, newPath + thisUrl );
3002	}
3003	});
3004 }

Wrapping the part that causes the error with if (typeof thisUrl != 'undefined') { fixes the error I'm seeing (see below) but I'm guessing the JQM team would rather figure out why thisUrl is undefined on line 2998.

//rewrite src and href attrs to use a base url
if( !$.support.dynamicBaseTag ) {
var newPath = path.get( fileUrl );
page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
var thisAttr = $( this ).is( '[href]' ) ? 'href' :
$(this).is('[src]') ? 'src' : 'action',
thisUrl = $( this ).attr( thisAttr );

if (typeof thisUrl != 'undefined') {

// XXX_jblas: We need to fix this so that it removes the document
// base URL, and then prepends with the new page URL.
//if full path exists and is same, chop it - helps IE out
thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );

if( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
$( this ).attr( thisAttr, newPath + thisUrl );
}
}
});
}

Cheers,
Dave