Results 1 to 7 of 7

Thread: javascript: changing the href

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    javascript: changing the href

    I am trying to write an after the fact fix for a bug in a blogging install. as it only happens once in a while and is rather minor I figred that javascript could cover the breach.

    The javascript changes any instance of domain#1 for the more correct domain#2

    Code:
    <script language="JavaScript1.2">
    <!--
    //This hack covers up for BAD code in CMS 
    // Edit these two values (mostly the second one should be your domain
    var fixdomain="myblog.com";
    var mydomain="lordmatt.co.uk";
    
    function dynamiclink(){
    for (i=0; i<=(document.links.length-1); i++) {
    
    document.links[i]=document.links[i].replace(fixdomain,mydomain);
    
    }
    }
    window.onload=dynamiclink;
    // -->
    </script>
    It doesn't work so I figure I done something wrong, but to be honest I suck at javascript. Sometimes it gives me errors in IE6 too.
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: javascript: changing the href

    Code:
    document.links[i].href=document.links[i].href.replace(fixdomain,mydomain);
    Works for me
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: javascript: changing the href

    Yep, and I can iterate through all the URLs useing alert (document.links[i].href); even though it's very annoying. But the changing urls to fix the odd few bad ones is just not happening. Not if FX or IE6


    Code:
    <script language="JavaScript1.2">
    <!--
    //This hack covers up for BAD code in CMS 
    // Edit these two values (mostly the second one should be your domain
    function dynamiclink(){
    var fixdomain="myblog.com";
    var mydomain="lordmatt.co.uk";
    for (i=0; i<=(document.links.length-1); i++) {
    //document.links[i].href=document.links[i].href.replace("lordmatt","mad-den");
    document.links[i].href=document.links[i].href.replace(fixdomain,mydomain);
    // alert (document.links[i].href);
    }
    }
    window.onload=dynamiclink;
    // -->
    </script>
    this is where I am and this is what must change

    Code:
    <link rel='prev' href='http://myblog.com/item/gregarius-reuters-oddly-enough'/>
    <link rel='next' href='http://myblog.com/item/most-lord-matt'/>
    and
    Code:
    <a href='http://myblog.com/member/Lord Matt'>
    <a href='http://myblog.com/category/advice'>
    There are one or two others like this in the archives but as it's all dynamicly generated I can't just do a search and replace...

    help...
    ?
    'What's this bit for anyway?
    For Jono

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: javascript: changing the href

    Well, even if its dynamically generated it still has to come form somewhere. Why not search where the data is coming from and fix it there?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: javascript: changing the href

    Quote Originally Posted by crptcblade
    Well, even if its dynamically generated it still has to come form somewhere. Why not search where the data is coming from and fix it there?
    Simply put I am fighting the mess that is a NeculusCMS fork called BLOG:CMS and although it looks good it has a few bugs that truely suck... and the code is a bugger to get into a mess of hacks and kludges and totally undocumented in PHP (Not my primary language) so I'd like to file a kludge of my own that will "fix" it for now.

    I can stick the JavaScript into the template files.

    http://lordmatt.co.uk - this is fine
    but check out the perma link on this old rant: http://lordmatt.co.uk/item/gregarius...sked-questions

    a quick view source show the javascript in place so I don't get what's happening.
    ?
    'What's this bit for anyway?
    For Jono

  6. #6

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: javascript: changing the href

    I've removed the JS for the time being. If any one knows of something less common that I have overlooked please speak up.

    Thanks

    -Matt
    ?
    'What's this bit for anyway?
    For Jono

  7. #7

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: javascript: changing the href

    I finally caved to the obviouse and found out how to fix the code (Get Necleus and stop buggering about with the usless slack hack that is Blog:CMS).

    Thanks for the help and if any one ever figures out what the bug was I'd be interested to know.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width