Avatar of leslieinva
leslieinva
Flag for United States of America asked on

Is there a tool to get a list of links on a web page?

I want a list of links on some pages.  It would love to have a two column list with the link name on the left & the actual URL on the right, but a plain text list of link names would do.  

How could I get this without editing the page itself?
Web Browsers

Avatar of undefined
Last Comment
Michel Plungjan

8/22/2022 - Mon
Michel Plungjan

I could write you a bookmarklet if you want
A link on the link bar you can click to get the list you want.
Would that be what you were thinking about?
Michel Plungjan

Or is this on your page?

Add

<script>
window.onload=function() {
  var links = document.links;
  var html = "<table>";
  for (var i=0,n=links.length;i<n;i++) {
    if (links[i].href!="") html += '<tr><td>'+
     links[i].textContent+
    '</td><td>'+links[i].href+
    '</td></tr>';
  }
  html +='</table>';
  var linksDiv = document.createElemen('div');
  linksDiv.style.height='250px';
  linksDiv.style.overflow='scroll';
  document.body.insertBefore(linksDiv,document.body.firstChild);
}
</script>

Open in new window

leslieinva

ASKER
Hi mplungjan,

How do I turn your script into a bookmarklet?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Michel Plungjan

Change
Window.onload=
To
javascript:(
and the last } to
})()
leslieinva

ASKER
After I do that, then how do I add it to my links bar?

I made the changes you suggested, then removed all the line breakes and pasted it into the URL for a bookmark.  I get no response from clicking on the bookmark.
Michel Plungjan

Sorry, forgot the double quotes and to add the innerHTML

Here

http://jsfiddle.net/mplungjan/GEPdP/
Drag the link in the bottom right field off to the links bar

And here is the code

<a href="javascript:(function() {var links = document.links;var html = '<table>';for (var i=0,n=links.length;i<n;i++) { if (links[i].href!='') html += '<tr><td>'+links[i].textContent+'</td><td>'+links[i].href+'</td></tr>';} html +='</table>';var linksDiv = document.createElement('div'); linksDiv.style.height='250px';linksDiv.style.width='500px'; linksDiv.style.position='absolute';linksDiv.style.top='0';linksDiv.style.zIndex=99999;linksDiv.style.overflow='scroll';linksDiv.innerHTML=html;document.body.insertBefore(linksDiv,document.body.firstChild);
})()">AllLinks</a>

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
leslieinva

ASKER
This is almost exactly what I need!  The only problem is how do I get this info off the screen into a text format of any kind?  I can't read it with the transparent background or use the info anywhere else as it displays now.

Can you have it create a separate HTML file, like the "Search Links" bookmarklet does at https://www.squarefree.com/bookmarklets/pagelinks.html#search_links
ASKER CERTIFIED SOLUTION
Michel Plungjan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
leslieinva

ASKER
YES!!!!

Many Thanks!!  

I'll give you more points if you can make the URL texts into real links in the output that open the linked pages into a new tab.
Michel Plungjan

You are welcome

With the points from this question I hit Overall Expert Point Total: 10,000,866
Giving me Savant Status.

jsFiddle with both bookmarklets

<a href="javascript:(function() {var links = document.links;var html = '<table>';for (var i=0,n=links.length;i<n;i++) { if (links[i].href!='') html += '<tr><td><a href=\''+links[i].href+'\'>'+links[i].textContent+'</a></td><td>'+links[i].href+'</td></tr>';} html +='</table>';var w=window.open('','_blank');if (w) {w.document.write(html);w.document.close()}
})()">AllLinks</a>

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23