Options

Can I change the link of a category thumb?

mk12345mk12345 Registered Users Posts: 63 Big grins
I would like to click a thumb or link of a category on my homepage, and have that open a new browser with a different website. How can I get accces to the href of a category thumb on my homepage?

Comments

  • Options
    mk12345mk12345 Registered Users Posts: 63 Big grins
    edited June 14, 2006
    The javascript below will do this. Just need to replace the <> items to match your needs

    Works nicely. I can now click on the thumb or the caption, and it will open a new browser showing the specified site.



    /************************************************************************************************/
    /********************** CODE TO REDIRECT THUMB AND IT's LINK ************************************/
    /************************************************************************************************/
    var sLinkIDPrefix = '<LAST to override want I that link of part>';
    var aLinkInfo = new Array();
    aLinkInfo[0] = '<MY image>|<LINK to want redirect i>';

    function Redirect2URL(e)
    {
    var oSourceElement = (document.all?window.event.srcElement:e.target);
    // Check element type, if not a hyperlink or image do nothing
    if ((oSourceElement.src) || (oSourceElement.href))
    {
    // Check hyperlink for ID Prefix
    if(oSourceElement.href)
    {
    if ((oSourceElement.href.indexOf(sLinkIDPrefix) > 0) || (oSourceElement.href.indexOf('<MY image>')))
    {
    // Reassign Href value to array value
    if((oSourceElement.src) && (oSourceElement.src.indexOf('<MY image>')))
    {
    oSourceElement.parentElement.target='_new';
    oSourceElement.parentElement.href='<LINK to want redirect i>';
    }
    else
    {
    oSourceElement.target='_new';
    oSourceElement.href='<LINK to want redirect i>';
    }

    }
    }
    }
    }
    //Create OnClick Event Listener
    document.onclick = Redirect2URL;


    mk12345 wrote:
    I would like to click a thumb or link of a category on my homepage, and have that open a new browser with a different website. How can I get accces to the href of a category thumb on my homepage?
  • Options
    AndyAndy Registered Users Posts: 50,016 Major grins
    edited June 14, 2006
    mk12345 wrote:
    The javascript below will do this. Just need to replace the <> items to match your needs
    can we see it in action? <img src="https://us.v-cdn.net/6029383/emoji/ear.gif&quot; border="0" alt="" >
  • Options
    mk12345mk12345 Registered Users Posts: 63 Big grins
    edited June 15, 2006
    Actually, it had some bugs... Here it is:

    function Redirect2URL(e)
    {
    var oSourceElement = (document.all?window.event.srcElement:e.target);

    // Check element type, if not a hyperlink or image do nothing
    if ((oSourceElement.src) || (oSourceElement.href))
    {
    if ((oSourceElement.href) && (oSourceElement.href.indexOf('MyUniqueCaptionLinkString') > 0)) // Hyperlink
    {
    oSourceElement.target='_blank';
    oSourceElement.href='http://www.MyNewLink.com';
    }
    else if (oSourceElement.parentNode.href.indexOf('MyUniqueCaptionLinkString')) // Image
    {
    oSourceElement.parentNode.target='_blank';
    oSourceElement.parentNode.href='http://www.MyNewLink.com';
    }
    }
    }

    //Create OnClick Event Listener
    document.onclick = Redirect2URL;


    Andy wrote:
    can we see it in action? ear.gif
  • Options
    mpmcleodmpmcleod Registered Users Posts: 288 Major grins
    edited June 15, 2006
    mk12345 wrote:
    Actually, it had some bugs... Here it is:

    function Redirect2URL(e)
    {
    var oSourceElement = (document.all?window.event.srcElement:e.target);

    // Check element type, if not a hyperlink or image do nothing
    if ((oSourceElement.src) || (oSourceElement.href))
    {
    if ((oSourceElement.href) && (oSourceElement.href.indexOf('<any unique="" text="" in="" your="" existing="" link="">') > 0)) // Hyperlink
    {
    oSourceElement.target='_blank';
    oSourceElement.href='<your new="" link="">';
    }
    else if (oSourceElement.parentNode.href.indexOf('<any unique="" text="" in="" your="" existing="" link="">')) // Image
    {
    oSourceElement.parentNode.target='_blank';
    oSourceElement.parentNode.href='<your new="" link="">';
    }
    }
    }

    //Create OnClick Event Listener
    document.onclick = Redirect2URL;

    Do you have a gallery where we could see it working?
    </your></any></your></any>
    -- Mike

    smugmug nickname: mpmcleod
    http://www.michaelmcleod.com/
  • Options
    mk12345mk12345 Registered Users Posts: 63 Big grins
    edited June 15, 2006
    I do but... I have it all password protected due to privacy conerns. What it does is intercept the click event, and see if the click was on either a particular thumb link, or the caption link below the thumb. It does this by hard-coding the image name and harding a unique portion of the caption link. When it determines the click was on the particular thumb or link, it launches a new browser with the specified link. It has been tested for both IE and Firefox. Try it out - it's simple to add and remove.
    mpmcleod wrote:
    Do you have a gallery where we could see it working?
    </YOUR></ANY></YOUR></ANY>
Sign In or Register to comment.