Lame hack of the URL-inserter

Discussion corner for Developers of Serendipity.
Post Reply
Marinmo

Lame hack of the URL-inserter

Post by Marinmo »

I'll admit into sucking at javascript. The idea isn't even really new or anything, but it not beeing default annoyed me;
When making an URL by using the nifty javascript that's built in, there is no

Code: Select all

target="_blank"
by default. There should be - if I were to decide ofcourse. Clicking a link doesn't mean I want to surf away from the current site I am browsing, and with s9y:s system of having an exit-URL on the same domain before actually redirecting renders all TBE (for Firefox) features useless.

So I wrote this - I know - lame hack (taken from serendipity_editor.js - anyone is ofc free to use this code if they are experiencing the same annoyance as me)

Code: Select all

function wrapSelectionWithLink(txtarea) {
    var my_link = prompt("Enter URL:","http://");
    var my_target = prompt("Enter Target:","target=_blank");

    if (document.all && getIESelection(txtarea) == "" ||
         document.getElementById && getMozSelection(txtarea) == "") {
        var my_desc = prompt("Enter Description", '');
    }

    if (my_link != null & my_target!= null) {
        lft = "<a href=\"" + my_link + "\" \"" + my_target + "\">";
        if (my_desc != null && my_desc != "") {
            rgt = my_desc + "</a>";
        } else {
            rgt = "</a>";
        }
        wrapSelection(txtarea, lft, rgt);
    }

    return;
}
There's still one problem that needs to be addressed; using a prompt isn't really the ideal solution - it had to do though since I am/was tired while writing this and couldn't get the variables to post properly when inserted directly into the

Code: Select all

lft = "<a href=\"" + my_link + "\" \"" + my_target + "\">";
line. Sorry, someday I might care enough to do this.

Output of all this is;

Code: Select all

<a href="http://www.marinmo.net" "target=_blank">Marinmo.net</a>
which ofc is not good since the whole "target=_blank" is within' "s, which should not be necessary - any webdeveloper will prefer target="_blank".

If any of the developers, or me, comes up with a better solution for this (there must be), I would appreciate if they would post it here and include it in the next stable, if they find it reasonable (they should! ;)).
Marinmo (too lazy to reg)

Post by Marinmo (too lazy to reg) »

And this is for 0.7.1, so it might already have been fixed in a later release/CVS.

Needless to say - I don't run unstable versions on my "official" site. :)
jhermanns
Site Admin
Posts: 378
Joined: Tue Apr 01, 2003 11:28 pm
Location: Berlin, Germany
Contact:

Post by jhermanns »

First of all, target is not a valid attribute in xhtml (but you don't have to go the xhtml way, so...). But then again, why do you want to force user's browser-behaviour? If the user wants to open it in a new window or a new tab, trust him, he will. And if not, he won't.

Trying to force him will a) not work and b) annoy your user. So why not leave it up to him?

:shock:
Last edited by jhermanns on Tue Feb 15, 2005 10:30 am, edited 1 time in total.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Thanks for the patch! It will surely be useful for people wanting this.

However our developers are not fond of putting this into the release. We like to support the concept the W3C supports by deprecating the target attribute.

It should be left up to browsers and users on how to open links. If a user wants to see a link in a new page, he can click so. I for one hate it when a page directs me to a new page and swamps my desktop.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Marinmo

Post by Marinmo »

jhermanns wrote:But then again, why do you want to force user's browser-behaviour? If the user wants to open it in a new window or a new tab, trust him, he will. And if not, he won't.

Trying to force him will a) not work and b) annoy your user. So why not leave it up to him?

:shock:
I for one presume that everytime I click a link, especially to an external site, the webmaster understands that I, by this action, do not necessarily want to leave his site. Maybe I am going to check sources, or maybe I'm just going to check "hey, I thought (link)this(/link) was funny" - EITHER way not opening a new window for a link, and I am focusing on the ones that leads to external sites here, is just annoying. I NEVER want it to open in the same browser window - yes, hitting the back-button is too much work for me, so don't even bother to bring it up. I for one am thankful for the people who've since long realized this fact and use target="_blank". If I were to leave the site I was browsing I can close the window if the link I just clicked turns out to open in a new window. Without any browser bashing intencies: but then again I use Firefox and can open many tabs in one window, making my taskbar stay clean at all times. It should be noted that I did the same thing back when using IE.

But then again, all this is opinions. We have a saying in Sweden; "smaken är som baken" - "the taste is like the butt" (rhymes in Swedish, needless to say), implying that everyone has their own taste and there always will be people to disagree with it.

About target not beeing xhtml: I don't care. :D I am not very familiar with standards, and I don't really mind them as long as a page is rendered in the same way, no matter if you're using IE, Opera, Mozilla or any other browser. It seems very dumb to me target is not in the specification, but then again I'm the clueless nobody here. :)
Marinmo
Regular
Posts: 11
Joined: Tue Feb 15, 2005 1:11 pm

Post by Marinmo »

(and yes, by now I've regained strenght and registred (mostly to be able to edit my own posts, frankly). behold. ;))
255 characters is not enough.
Post Reply