Solved

Bookmarket to show a page's links & URLs with links on the URLs

Posted on 2012-03-18
3
190 Views
Last Modified: 2012-04-04
I have a great bookmarklet created by one of the experts here, mplungjan, that will list all the links on a page & the URLs for each link.  This is the code:
javascript:(function()%20{var%20links%20=%20document.links;var%20html%20=%20'<table>';for%20(var%20i=0,n=links.length;i<n;i++)%20{%20if%20(links[i].href!='')%20html%20+=%20'<tr><td>'+links[i].textContent+'</td><td>'+links[i].href+'</td></tr>';}%20html%20+='</table>';%20var%20w=window.open('','_blank');if%20(w)%20{w.document.write(html);w.document.close()};})()

Open in new window


For 350 points, can you modify this so that:
1) The URL text on the right in the output is linked to the actual pages so that the pages open up in a new tab  
2) Let me know how to modify it if I wanted the URLs to open in a new browser instead of new tab.

For 500 points, add these features from the "search links" bookmarket at https://www.squarefree.com/bookmarklets/pagelinks.html#search_links
3) Limit the output by a string if desired
4) Put the link for the source page on the top of the output
5) Put numbers on each line in the output

Thanks!
0
Comment
Question by:leslieinva
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
nap0leon earned 500 total points
ID: 37735281
URLs are links:
javascript:(function()%20{var%20links%20=%20document.links;var%20html%20=%20'<table>';for%20(var%20i=0,n=links.length;i<n;i++)%20{%20if%20(links[i].href!='')%20html%20+=%20'<tr><td>'+links[i].textContent+'</td><td><a href="'+links[i].href+'">'+links[i].href+'</a></td></tr>';}%20html%20+='</table>';%20var%20w=window.open('','_blank');if%20(w)%20{w.document.write(html);w.document.close()};})()

Open in new window


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

Open in new window

(to make them all open in the same new window, change "_blank" to whatever you want the name of the new window to be)

Adding the Originating URL to the top as an H1 tag:
javascript:(function()%20{var%20links%20=%20document.links;var%20html%20='<h1>'+document.location+'</h1><table>';for%20(var%20i=0,n=links.length;i<n;i++)%20{%20if%20(links[i].href!='')%20html%20+=%20'<tr><td>'+links[i].textContent+'</td><td><a href="'+links[i].href+'"%20target="_blank">'+links[i].href+'</a></td></tr>';}%20html%20+='</table>';%20var%20w=window.open('','_blank');if%20(w)%20{w.document.write(html);w.document.close()};})()

Open in new window


No clue on the line numbers.
No clue what you mean by "limit the string if I want"  You mean limit the displayed URL to only the first N characters?  If so, here is an example that limits it to the first 20 characters.  
javascript:(function()%20{var%20links%20=%20document.links;var%20html%20='<h1>'+document.location+'</h1><table>';for%20(var%20i=0,n=links.length;i<n;i++)%20{%20if%20(links[i].href!='')%20html%20+=%20'<tr><td>'+links[i].textContent+'</td><td><a%20href="'+links[i].href+'"%20target="_blank">'+links[i].href.slice(0,20)+'</a></td></tr>';}%20html%20+='</table>';%20var%20w=window.open('','_blank');if%20(w)%20{w.document.write(html);w.document.close()};})()

Open in new window


To change the number of characters, edit this part
links[i].href.slice(0,20)

Open in new window

0
 

Author Comment

by:leslieinva
ID: 37735335
OK,  we're up to 400 points.

To see what I mean by "Limit the output by a string if desired" try out the bookmarklet called "search links" at https://www.squarefree.com/bookmarklets/pagelinks.html#search_links.  
It prompts for a string (word or phrase), and then lists links on the page that contain that string in a new window. The string may appear in the link's target url or in its anchor text. If you leave the prompt blank, all links on the page will be listed.  It also add line numbers.
0
 

Author Closing Comment

by:leslieinva
ID: 37806493
Still looking for the part that would allow filtering the output by a dynamically entered string.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question