Member
From: York, England
Registered: 2005-11-04
Posts: 608
I've been thanked 11 times.
Offline
On the face of it, this might seem like a really dunb thing to want to do, but honestly its not!!
Ok, Ive got this javascript:
Code: javascript
<script language="JavaScript1.2">
<!--
/*
Link Extractor Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/
function extractlinks(){
if (document.all||document.getElementById){
if (document.all)
var links=document.all.tags("A")
else if (document.getElementById)
var links=document.getElementsByTagName("A")
var total=links.length
var win2=window.open("","","menubar,scrollbars,status")
win2.document.write("<h2>Total Links="+total+"</h2><br>")
for (i=0;i<total;i++){
win2.document.write('<a href="'+links[i]+'">'+links[i].innerHTML+'</a><br>')
}
win2.document.close()
}
}
//-->
</script>
<button onClick="extractlinks()">Extract Links</button>
As you can see, its from dynamic drive.
Anyway, what that does is it extracts all the links from a page, opens a popup window and renders those same links to the popup.
What Id like it to do is to extract all the links from a page and render them to the SAME page. This should make all the links that were there disappear, being replaced by the newly rendered ones. Hopefully, users would never see the original links. Ive been putting the call to extractlinks() in an OnLoad in the body tag.
Told you it was dumb, but it could prove quite useful if I can get it to do what I want. Anyone got any ideas?
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
what's wrong with doing it in php?
Member
From: York, England
Registered: 2005-11-04
Posts: 608
I've been thanked 11 times.
Offline
Ah!
the links are served to the page using javascript. Viewing source doesnt show any anchour tags, just a call to an offsite javascript.
When i put the above script on the same page, the popup renders all the links properly, giving me the opportunity to add something........
Member
From: Loughborough, United Kingdom
Registered: 2006-04-14
Posts: 805
I've been thanked 13 times.
Offline
well rather than create the new window you can just build up a value that you return through the dom
Code: html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<title>Js stuff</title>
</head>
<body>
<a href="http://www.moo.com/">Moo</a>
<script type="text/javascript">
<!--
/*
Link Extractor Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/
function extractlinks(){
if (document.all||document.getElementById){
if (document.all)
var links=document.all.tags("A")
else if (document.getElementById)
var links=document.getElementsByTagName("A")
var total=links.length
// var win2=window.open("","","menubar,scrollbars,status")
// win2.document.write("<h2>Total Links="+total+"<\/h2><br>")
results = "<h2>Total Links="+total+"<\/h2><br>";
for (i=0;i<total;i++){
// win2.document.write('<a href="'+links[i]+'">'+links[i].innerHTML+'<\/a><br>')
results += '<a href="'+links[i]+'">'+links[i].innerHTML+'<\/a><br>';
}
document.getElementById("div").innerHTML = results;
// win2.document.close()
}
}
//-->
</script>
<button onClick="extractlinks()">Extract Links</button>
<div id="div"> </div>
</body>
</html>
Got a train to catch now, hope this works.
Cheers
NoSting Hosting - Brightside Hosting Ltd: Member of Nominet / eNom ETP
^^^ Now with over 400 free templates, ShoutCast, LAME + FFMPeg
Ringtones - Palace Marketing Ltd: D2C and B2B mobile content since 2002
Member
From: York, England
Registered: 2005-11-04
Posts: 608
I've been thanked 11 times.
Offline
Oh YEAH!!!!!
Nice one mobtex!!
Ive had to put the original javascript links into the div, so the newly rendered links overwrite them.
Spot on mate, cheers
Member
From: York, England
Registered: 2005-11-04
Posts: 608
I've been thanked 11 times.
Offline
Ah, problem!
The links rendered to the page do contain anything I have added, and it does format the page how I set it to format, but the view source still shows the original javascript links.
When it was opening a new window, the source showed proper anchours. I could really do with it completely overwriting the original.
Any ideas?
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
Do you want a find and replace function to turn all the
<a href=#'>.....</a> type links into js cloaked links?
And, o you want this done serverside so that nothing sees the original links?
I think i can help but i really have no idea what you actually want 
Member
From: York, England
Registered: 2005-11-04
Posts: 608
I've been thanked 11 times.
Offline
nearly, just the complete opposite northie.
I get a javascript link that I put on a page. When that gets called to the screen it produces an ever changing list of about 10-15 links. But it's always the same javascript, just the links change.
I need them to end up on the screen how and where I want them and with real <a href=""> <img src=""> when the source is viewed.
i suppose I am trying to 'cloak' something, but not in a dark way.
it's more so that A) I can format the links and add some behaviour to them and B) so my competition doesn't know where Ive got this feed from or how I did it.
TBH, i would prefer serverside, but I couldn't get php to do anything with it. and we all know you're the PHP man!!
(no diss mobtex, its always you who comes up with the JS as you are the javascript man!!)
If you 2 got together, think of the AJAX babies you could make!! 
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
Code: php
PM me the js link / feed and i'll have a look
Member
From: York, England
Registered: 2005-11-04
Posts: 608
I've been thanked 11 times.
Offline
Sent mate, cheers! 
Member
From: Loughborough, United Kingdom
Registered: 2006-04-14
Posts: 805
I've been thanked 13 times.
Offline
All this extraction of hyperlinks kinda got me thinking and the next thing i know I've made a new toy:
Anchor Text Link Tool
Thanks for the inspiration folks!
NoSting Hosting - Brightside Hosting Ltd: Member of Nominet / eNom ETP
^^^ Now with over 400 free templates, ShoutCast, LAME + FFMPeg
Ringtones - Palace Marketing Ltd: D2C and B2B mobile content since 2002
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
mobtex wrote:
All this extraction of hyperlinks kinda got me thinking and the next thing i know I've made a new toy:
Anchor Text Link Tool
Thanks for the inspiration folks!
sweet - i've started building something similar that will also extract keywords from the page and match them to the link text and offer a topic:reputation score
Member
From: Loughborough, United Kingdom
Registered: 2006-04-14
Posts: 805
I've been thanked 13 times.
Offline
i've made it log the urls entered and added adsense to the pages, the history should then show relevant ads to the content of the page.
the script i've made up doesn't handle 301s and has a few other little bugs but this topic got me thinking and i enjoyed making a new tool.
i also added the option to get the title of the target page to see how they match. not gone as far as the keywords used but that's a sweet idea!
i'm sure i could spend more time on it and make it slicker but real work beckons!
NoSting Hosting - Brightside Hosting Ltd: Member of Nominet / eNom ETP
^^^ Now with over 400 free templates, ShoutCast, LAME + FFMPeg
Ringtones - Palace Marketing Ltd: D2C and B2B mobile content since 2002
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
i broke it
Member
From: Loughborough, United Kingdom
Registered: 2006-04-14
Posts: 805
I've been thanked 13 times.
Offline
lol yours or mine?
NoSting Hosting - Brightside Hosting Ltd: Member of Nominet / eNom ETP
^^^ Now with over 400 free templates, ShoutCast, LAME + FFMPeg
Ringtones - Palace Marketing Ltd: D2C and B2B mobile content since 2002
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2860
I've been thanked 85 times.
Offline
mobtex wrote:
lol yours or mine?
yours
Member
From: Loughborough, United Kingdom
Registered: 2006-04-14
Posts: 805
I've been thanked 13 times.
Offline
thanks for such an detailed error report! it was most helpful
NoSting Hosting - Brightside Hosting Ltd: Member of Nominet / eNom ETP
^^^ Now with over 400 free templates, ShoutCast, LAME + FFMPeg
Ringtones - Palace Marketing Ltd: D2C and B2B mobile content since 2002
| Never |


