Ticket #14127 (closed enhancement: worksforme)

Opened 2 years ago

Last modified 2 years ago

Dashboard feed widgets should open entries in new tabs

Reported by: IndigoJo Owned by:
Priority: normal Milestone:
Component: General Version: 3.0
Severity: normal Keywords:
Cc:

Description

The widgets which track feeds like WP Planet, etc. and incoming links should open entries in new tabs rather than replacing the WP admin interface, or at least provide an option for this. Only internal links should open in the same tab, so that the tab remains reserved for administering the site, rather than for viewing extraneous content (not all of it relevant to the site itself).

Change History

  • Status changed from new to closed
  • Resolution set to worksforme
  • Milestone Awaiting Review deleted

What prevents you from doing Right-Click -> Open in new tab (or even scroll-press)?

If you want to enable this functionality for an unknowing client, you should install a plugin that opens _all_ external links from the admin in a new window. This can be achieved with a few lines of javascript.

And here is said javascript:

jQuery(document).click(function(ev) {
	var url = jQuery(ev.target).attr('href'), undefined;

	if ( undefined == url )
		return;

    if ( 0 != url.indexOf(location.protocol + '//' + location.host) ) {
		window.open(url);
		return false;
	}
});

scribu's right: there's no reason to make a general penalty for users so long as you have the scroll click available.


	if ( undefined == url )
		return;

What does that get you that if ( ! url ) doesn't?

    if ( 0 != url.indexOf(location.protocol + '//' + location.host) ) {
		window.open(url);
		return false;
	}

The problem is that in the WP admin, the internal links are not absolute, so you'll be opening them in new windows too.

comment:4 follow-up: ↓ 6   scribu2 years ago

What does that get you that if ( ! url ) doesn't?

You're right.

The problem is that in the WP admin, the internal links are not absolute, so you'll be opening them in new windows too.

Good observation, yet it works, because they're automatically translated into absolute URLs in JavaScript land.

comment:6 in reply to: ↑ 4   filosofo2 years ago

Replying to scribu:

Good observation, yet it works, because they're automatically translated into absolute URLs in JavaScript land.

Yes and no, depending on what you're getting and the client you're doing it in.

Yes in IE--you get the full path. But in Firefox it depends:

  • The href property of the target has the full path.
  • But the "href" attribute has its actual value, here not absolute.

In this case

jQuery(ev.target).attr('href')

is equivalent to

ev.target.getAttribute('href') // relative path

not

ev.target.href // absolute path

Thanks for pointing that out. :)

Updated the tutorial.

Note: See TracTickets for help on using tickets.