Solved

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

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

631 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