Opened 12 years ago

Closed 10 years ago

Last modified 10 years ago

#4836 closed enhancement (fixed)

Self refering href only partially detected

Reported by: aschild Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.tabs Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:


Given the following constelation:

Page URL: MyPage.html

In the page source we have this:

<ul class="navtab"> <li><a href="MyPage.html#Overview">Overview</a></li> <li><a href="MyPage.html#Images">Images</a></li> </ul>

The 1.7.2 version of UI.tabs does not detect that we point to ourself and loads the page twice and the result is not what we expect.

The solution is to look if the href is only a page name, and if yes, look if it's identical tou our own url.

Here the code which fixes this problem, it starts arround line 85 of the ui.tabs.js

			// For dynamically created HTML that contains a hash as href IE < 8 expands
			// such href to the full page url with hash and then misinterprets tab as ajax.
			// Same consideration applies for an added tab with a fragment identifier
			// since a[href=#fragment-identifier] does unexpectedly not match.
			// Thus normalize href attribute...
			var hrefBase = href.split('#')[0], baseEl;
			var onlyLocation= location.toString().split('#')[0];
			var locArray= onlyLocation.split('/');
			var lastElement= locArray[locArray.length-1];
			if (hrefBase && (hrefBase === location.toString().split('#')[0] ||
					(baseEl = $('base')[0]) && hrefBase === baseEl.href) ||
					(hrefBase.indexOf('/') == -1 && hrefBase == lastElement)
				) {
				href = a.hash;
				a.href = href;

Would be great if it could be included in a future version. There is still one case not catched, when the href is "./MyPage.html", then it still goes wrong, but so far we did not have that case.

Attached is a diff

Attachments (1)

ui.tabs.js.diff (385 bytes) - added by aschild 12 years ago.
Diff file with the enhancement

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by aschild

Attachment: ui.tabs.js.diff added

Diff file with the enhancement

comment:1 Changed 11 years ago by Jörn Zaefferer


Can't you just fix those hrefs to include only the hash?

comment:2 in reply to:  1 Changed 10 years ago by pkruithof

Replying to joern.zaefferer:

Can't you just fix those hrefs to include only the hash?

Probably, but I imagine there are template engines that automatically formats URL's to start from the site root. Mine doesn't, but this 'bug' cost me an hour to figure out because I do format my URL's this way. My point being that this is unexpected behaviour.

comment:3 Changed 10 years ago by Scott González

Resolution: fixed
Status: newclosed

Tabs: Fixed detection of local vs. remote tabs. Fixes #4941 - Mishandling of base tag. Fixes #4836 - Self refering href only partially detected.

Changeset: 18a3b539882835ecc78ed976a7d9e830c128fd96

comment:4 Changed 10 years ago by Scott González

Milestone: 1.next1.9
Note: See TracTickets for help on using tickets.