Everything2
Near Matches
Ignore Exact
Full Text
Everything2

How to (nearly) link to external sites

created by spiregrain

(idea) by spiregrain (3.1 hr) (print)   ?   (I like it!) 2 C!s Wed Jun 06 2001 at 16:35:03

Almost everyone knows that, in order to prevent e2 from turning into a web log, it is impossible to create links to external sites in your writeups. Often people include urls in their writeups, and I've hacked this idea of nate's to enable browsers to follow these links. You can add the following javascript as a new link in your toolbar. To do this, create a new toolbar button, and replace the URL (the "web address") with one of the following incantations:

To open in the same window:

javascript:Q=document.selection.createRange().text;if(Q)location.href=Q;
Or for a new window:
javascript:Q=document.selection.createRange().text;if(Q)(window.open(Q))

Now, if you hilight a url in a writeup and click your new toolbar-button, your browser will attempt to locate and load that page. Note that this requires the selected url to begin with http:// or some other protocol specifier.


Update: 31/10/2002
Thanks to the mighty, mighty call for suggesting the .replace(/\s+/g,'') segment, which removes whitespaces from the URLs. This works fine in Mozilla and similar browsers, and should be OK in IE, too. You can try it by putting it into on of the above snipets, just after the last q. No spaces.

If you want to make the system work correctly with strings that don't begin with a protocol specifier, you can additionally add a ";if(!q.match(/^\w+:\/\//g))q='HTTP://'+q" before the ";if". This will insert "http://" before the selected text in Netscape or Mozilla, but it doesn't seem to work for me in IE.


Update: 23/11/2004
If you have the excellent Mozilla Firefox or a related browser, you should have a look at the "Linkify" and "Jump Link" extensions on update.mozilla.org. The former converts text URLs into green, clickable hyperlinks, and the latter makes it easy to follow pipe-linked URLs, like the ones that crop up in the catbox.


Update: 20/10/2005
Thecoderwho has developed a replacement catbox nodelet. It has several cool features, including generation of external hyperlinks from linked and pipe-linked URLs. Give it a whirl at his homenode. here. Thecoderwho may be a pseudonym.


You can test it here:
http://www.google.com
http://www. google.com

(thing) by Anml4ixoye (3.2 wk) (print)   ?   (I like it!) Tue Apr 01 2003 at 19:44:23

From the let's-make-it-crazy-obsfucated-department

With the current nodelet craze, and everyone wanting a way to take a pipelink to Google, I decided to make a way to do it. First I played around with the IE context menu, but couldn't find a way to pass the link back to it, and I wanted it to be cross-browser compatible. But using the following code you can highlight a link you want to go to that has a web address, push the button, and be transported there in a new window.

One problem. The code (as you can see below) is long. Too long for our notelet nodelet, especially for a level 3 noder like myself. *BUT* the nodelet allows you to import scripts (It also allows you to use IFRAMES - see my homenode another nifty thing). So see below for how to work this into your nodelet.

(This has been tested in Phoenix 0.5 and IE 5.5 and IE6. Let me know of any issues)


Technical Description

When you push the button after highlighting the text, the script goes through the page and looks for a link that has the same text. For example, if there was a link:


<a href="http://www.everything2.com?node=www.google.com">Soy Soy Soy!</a>

If you highlighted "Soy Soy!" and pushed the button, the script would look for a link that used - somewhere in the text of the link - that term. It would then open a new window and send you to the address that is after "node=" in the href.

*Note* - This script used to return back a listing of all links in the document that matched the text you highlighted. E2 has too many links and it crashed my browser at first. I am working on a fix for this.


Nodelet

Here is how I have it in my notelet nodelet. If you are concerned about code coming from someone else's server please feel free to copy it to wherever you feel it's safe.


<script language="javascript" src="http://www.cornetdesign.com/alertLink.js">
</script>
<form><input type="button" value="Go Out!" onClick="javascript:goOut()"></form>


The Code

Here is the actual code. It consists of two functions just to clean it up a bit


function goOut(){
var l;

if(document.getSelection){
l = window.getSelection();
ie=0;
}else{
l = document.selection.createRange().text;
ie=1;
}


if(l != ""){
var linksFound = 0;
var arrLinks = new Array();
var theLinks = document.links;
for(i=0;i<theLinks.length;i++){
if(ie){
	if(theLinks[i].outerText.indexOf(l) >= 0){
		//alert("Link!");
		arrLinks[linksFound++] = parseURL(theLinks[i].href);
		break;
	}
}else{
	if(theLinks[i].text.indexOf(l) >= 0){
		//alert("Link!");
		arrLinks[linksFound++] = parseURL(theLinks[i].href);
		break;
	}else{
		strTest += theLinks[i].text+"|";
	}
}
}
if(arrLinks.length > 0){
theWinProps = "width=400,height=300,scrollbars=1,resizable=1,menubar=1,status=1";
theWin = open("","",theWinProps);
theWinDoc = theWin.document;
if(arrLinks.length = 1){
	theWinDoc.location = arrLinks[0];
}else{
	theWinDoc.writeln("Multiple Links Found that matched that selection:<br>")
	for(j=0;j<arrLinks.length;j++){
		theWinDoc.writeln("<a href=\""+arrLinks[j]+"\">"+arrLinks[j]+"</a><br>");
	}
}
}else{
alert("No links were found that matched that text");
alert("Text searched for: '"+l+"'");
alert(strTest);
}
}else{
alert("You must select a link to go to");
}
return false;
}

function parseURL(strURL){
//alert(strURL);
//This finds the node that is pointed to from node= in the querystring
var returnString = "http://www.everything2.com";

var qMarkLoc = strURL.indexOf("?")+1;
qString = strURL.slice(qMarkLoc);
arrParams = qString.split("&");
for(i=0;i<arrParams.length;i++){
if(arrParams[i].slice(0,5) == "node="){
returnString = arrParams[i].slice(5);
//alert(returnString);
break;
}else{
alert(arrParams[i].slice(0,5));
}
}

if(returnString.indexOf("http://") < 0){
returnString = "http://"+returnString;
}

//alert(returnString);
return returnString;
}


Enjoy, and feel free to contact me with any questions or suggestions.


printable version
chaos

Frowning on external links, then smiling, then bouncing them a little edev: Devon's idea about outside linking Javascript for Windows-IE Everything Search Button Pictures of Everythingians
Gonna go buy me some Jesus! The Limited Edition "Participate in Your Own Manipulation" Poster Toolbar /borg button Searching E2 from a Windows MSIE address bar
blog Netscape E2 User Search Notelet nodelet utilities How Can You Be in Two Places at Once When You're Not Anywhere at All?
bookmarklet e2izer How to link to individual user searches Notelet nodelet utility for following external links in the chatterbox
Why I did what I did Beer Batter Pancakes Hack Logical HTML style harassment
DJ Assault Liminal Google JavaScript
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Little presents from the Node Fairy:
If you could see what your cars are made of, people, you'd shoot yourselves.
Some vampires actually get pissed when you tell them to Have A Nice Day
fibromyalgia
Spam
Calypso
Terminating a pregnancy due to Down Syndrome
War on Iraq 2002
Gurkha
Somewhere there's a god who wants me
Jessica Lynch
pregnancy test
protein
physics
New Writeups
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
stainedglass
1(fiction)
kalen
Three "T"s(idea)
octillion369
Undead(idea)
archiewood
Ico(fiction)
Heisenberg
Why I love Everything2(log)
octillion369
Death Knight(person)
XWiz
Are you hoping for a miracle?(review)
santo
The Host(review)
LostPsion
"Shut the Fuck Up" Theaters(idea)
beatrice
You've been slowly taking me over for nearly a year, do you know that?(idea)
Berek
YouTube(thing)
E2 is a by-product of the existence of The Everything Development Company