• # March 13, 2012 at 3:02 am

    Is it possible to detect if there is a text URL that has been wrapped by the anchor tag, so I can manage the target of this snippet. I’ve tried Googling but nothing.

    Here is my Fiddle:

    Thank you very much.

    # March 13, 2012 at 10:41 am

    Hey Hompimpa,
    Not exactly sure what you’re trying to so here?
    is it change the target of the existing anchor on the page?

    # March 13, 2012 at 9:52 pm

    This reply has been reported for inappropriate content.

    This snippet is used to change the plain URL becomes active URL automagically. But when the real URL caught they are become a little CRAZY!

    <a href="">

    I’ve tried this:


    so the element that not useful will be removed. But I think this way is not quite cute.

    # March 14, 2012 at 9:41 am

    This reply has been reported for inappropriate content.

    I got it!
    So, instead of replacing the matched string into a link, it would be better if we turn it into a element first. Then, when all the matched strings has been wrapped by , remove all the original link that might wrap this element.
    And the last, just replace the span with an anchor tag.
    It works! YAY!

    // Detect links pattern
    var exp = /(b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig;

    // Wrap the matched strings with ``
    $('body').html($('body').html().replace(exp, "$1"));

    $('.fake-link').each(function() {
    // Extra job: Check if parent is an anchor
    if ($(this).parent().is('a')) {
    // If `true`, then unwrap the original anchor which has been written by default from `.fake-link`
    // Replace `.fake-link` with an anchor tag
    $(this).replaceWith('' + $(this).text() + '');

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.