PDA

Click to See Complete Forum and Search --> : javascript: changing the href


Matt_T_hat
Sep 21st, 2005, 05:22 AM
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

<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.

crptcblade
Sep 21st, 2005, 07:39 AM
document.links[i].href=document.links[i].href.replace(fixdomain,mydomain);

Works for me

Matt_T_hat
Sep 21st, 2005, 12:38 PM
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


<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

<link rel='prev' href='http://myblog.com/item/gregarius-reuters-oddly-enough'/>
<link rel='next' href='http://myblog.com/item/most-lord-matt'/>
and
<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...

crptcblade
Sep 21st, 2005, 01:33 PM
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?

Matt_T_hat
Sep 21st, 2005, 01:51 PM
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-frequently-asked-questions

a quick view source show the javascript in place so I don't get what's happening.

Matt_T_hat
Sep 21st, 2005, 05:33 PM
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

Matt_T_hat
Sep 24th, 2005, 09:35 AM
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.