Menu
OK, so when i input text in textarea “
How can i make it like that..? Please help!
Yes, but i have no ideas how to do this... I need to find http i gues and then add <a> or something.. but i don't know how to do this.. ?The innerHTML version is much simpler but we don't go there.
Please help guys..[/quote]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Text to Link</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type='text/css'>
a:link.linkElem{font-weight:bold}
</style>
</head>
<body>
<form action="">
<p>
<textarea cols='50' rows='6' onkeyup='TextToLink.create("linkElem", this.value)'>Enter a URL here. http://</textarea>
</p>
</form>
<p>
<div id='linkElem'></div>
<script type='text/javascript'>
var TextToLink=
{
data:[/*28432973637269707465726C61746976652E636F6D*/],
create:function(elemId, inpStr)
{ <br/>
var str="", obj=this.data[elemId];
if( !this.data[elemId] )
{
obj=this.data[elemId]={}; <br/>
obj.opElem=document.getElementById(elemId);
<i> </i>while(obj.opElem.firstChild)
<i> </i> obj.opElem.removeChild(obj.opElem.firstChild);
<i> </i>(obj.link=document.createElement('a')).appendChild(document.createTextNode(""));
<i> </i>obj.link.target='_blank';
<i> </i>obj.link.className=elemId;
<i> </i>obj.opElem.appendChild(obj.link);
}
if( (str=inpStr.match(/(^|s)https?://.*(s|$)/)) )
obj.link.href=str=str[0]; <br/>
obj.link.replaceChild(document.createTextNode(str||""), obj.link.firstChild); <br/>
}
}
</script>
</body>
</html>
I like this site -http://www.webdeveloper.com/ and also i like this site -http://www.apple.com
But i don't like this site -http://www.unknown.com [/QUOTE]
I like this site -http://www.webdeveloper.com/ and also i like this site -http://www.apple.com
But i don't like this site -http://www.unknown.com/ [/QUOTE]
I like this site -http://www.webdeveloper.com/ and also i like this site -http://www.apple.com/
But i don't like this site -http://www.unknown.com/ [/quote]
I like this site -http://www.webdeveloper.com/ and also i like this site -http://www.apple.com/
But i don't like this site -http://www.unknown.com/ [/quote]
I also don't want any bbcodes here just this.. because it's not parsing urls automatically.. ? Please help..[/QUOTE]
var tempInput = inputtext;
var outputText = '';
var parsedURL = '';
var i = 0;
var tempIndex = 0;
while (i < inputtext.length-1) {
startindex = tempInput.indexOf('http');
if startindex==-1) {
outputText += tempInput.substr(i)
i = inputtext.length - 1;
}
else {
stopindex = tempInput.substr(startindex).length;
tempIndex = tempInput.substr(startindex).indexOf(' ');
if (tempIndex > 0) && (tempIndex < stopindex) stopindex = tempIndex;
tempIndex = tempInput.substr(startindex).indexOf('. ');
if (tempIndex > 0) && (tempIndex < stopindex) stopindex = tempIndex;
tempIndex = tempInput.substr(startindex).indexOf(', ');
if (tempIndex > 0) && (tempIndex < stopindex) stopindex = tempIndex;
if (startindex!=0) outputText += tempInput.substring(0, startindex - 1);
parsedURL = tempInput.substring(startindex, stopindex-1);
outputText += '<a target="_blank" href="' + parsedURL + '">' + parsedURL + '</a>';
i+= stopindex;
tempInput = tempInput.substr(stopindex);
}
[code=php] var newmsg = document.post.message.value;
String.prototype.parseURL = function()
{
return this.replace(/[A-Za-z]+://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&?/.=]+/gi, function(url)
{
return url.link(url);
});
};
newmsg = newmsg.parseURL();[/code]
I got error like this..
Error: syntax error
Source File: file:///C:/Users/QueenZ/Documents/hashboy.html
Line: 20, Column: 24
Source Code:
if (tempIndex > 0) && (tempIndex < stopindex) stopindex = tempIndex;[/QUOTE]
<i>
</i> if ((tempIndex > 0) && (tempIndex < stopindex)) stopindex = tempIndex;
good news guys! I found it!
Here is the code if someone else needs this too.
[code=php] var newmsg = document.post.message.value;
String.prototype.parseURL = function()
{
return this.replace(/[A-Za-z]+://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&?/.=]+/gi, function(url)
{
return url.link(url);
});
};
newmsg = newmsg.parseURL();[/code]
I found this on this website -http://www.simonwhatley.co.uk/parsing-twitter-usernames-hashtags-and-urls-with-javascript
Problem solved![/QUOTE]
Hi there, I'm trying to this exact same thing...how do you get that code to work with a textarea in a form? (the textarea I want to check has id/name="tips")
I tried adding an onClick to the submit button: onClick="document.write(tips.parseURL())", and also tried onSubmit, as well as trying just tips.parseURL() without the document.write
any ideas? (I'm not very good with Javascript so I don't really get what this code is doing or how to use it...)
Thanks in advance![/QUOTE]
<i>
</i><input type="button" onclick="useFunctions();" />
<i>
</i>function useFunctions() {
var tips = document.getElementById("tips");
tips.innerHTML = tips.innerHTML.parseURL();
}
i am getting a syntax error for the line:The // should be escaped as: //
return this.replace( (/[A-Za-z]+://[A-Za-z0-9-_]+.[A-Za-z0-9-_:%&?/.=]+/gi), function(url)
[/quote]
0.1.9 — BETA 5.8