Solved

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

Posted on 2012-03-18
3
189 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery-Javascript setAttribute function help 7 18
Make Session back to empty 9 30
javascript - insert into js doc help 2 19
send email part1 9 22
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

791 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