Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-03-18
3
Medium Priority
?
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
nap0leon earned 1500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

688 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