3 Years
Discussion Span
Last Post by happygeek

Here's something I just put together. It makes all outbound links on a page open in a new window, providing that nothing was already assigned to the onclick event. Is this the sort of thing you were thinking of?

function makeExternalLinksOpenWindow() {
    for (var i = 0; i < document.links.length; i++) {
        var theLink = document.links[i];
        if ((theLink.onclick === null) && (location.host !== findHost(theLink.href)))
            theLink.onclick = function () { window.open(this.href); return false; };

function findHost(urlString) {
    var match = urlString.match(/https?:\/\/(.+?)\//i);
    if (match && match.length >= 2)
        return match[1].replace(/:80$/, ""); // Normalize for port 80.
    return null;

I unconciously developed a habit of making a mental tree of all my pages open, and when my mind says "branch", I open it in a new tab, and when it says "dive" I open it in the same tab. Sometimes websites don't always handle "open in a new tab" well depending on how they implement normal clicking, breaking the "expected behaviour", even if the "expected behaviour" was not well designed.

Anyone else run into this?


Agree about expected behavior being to open in the same window. In fact, I read somewhere a few years ago that Google actually lowers search ranking for doing otherwise, because they consider it a factor in a subpar user experience. If you want to open a link in a new window, you're supposed to right click as the end-user.


If you want to open a link in a new window, you're supposed to right click as the end-user.

A lot of times, that really isn't the first instinct they have when it comes to opening links. I thought it would be useful because what if a new user/unregistered user clicks on a link, opens up on the same tab they are currently on, they exlore that link a bit and what happens next? They most likely do not come back. When having two tabs open, daniweb is always left open while the other link is open.


I get what you're saying, but the inherent notion of surfing the web means moving from link to link. If each link opened up in a new window, then you'd end up with 500 tabs and the back/forward buttons on your browser would be pointless.


I don't get the logic in the open a new tab argument. If people are taken to a resource that answers their question, and that was the oinly reason they were on DaniWeb, then they would not have come back to us immediately anyway (unless they wanted to say thanks, in which case I imagine they will do anyway.) If they wanted to continue browsing at DaniWeb then having to type in daniweb.com is hardly going to stop them no matter where they have been beforehand.

And, anyway, sites that buck the accepted defualt browsing convention of opening in the same window/tab without asking me what I want to do are likely not to get my return custom anyway. It's something that annoys the heck out of me.

Edited by happygeek

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.