Link to home
Start Free TrialLog in
Avatar of DBB
DBB

asked on

prevent links in text area

Hi,

What's the best way to disallow links in textarea inputs?

Thanks

Dbb
Avatar of DreamMaster
DreamMaster

Probably the best way, is to search for a part in the string that resembles any type of link and strip that part of it.

Regards,
Max.
Avatar of DBB

ASKER

Thought so,

I just wandered if there was a tag to use or something

Thanks

Dbb
Nope, there's nothing like a "strip links from textareas" tag...unfortunately.. ;)

Regards,
Max.
Avatar of DBB

ASKER

Didn't think so, ah well...

Dbb
this will stop all links in the texarea

<script>
function stripLinks(obj){
 reg=/<a[^>]+>[^>]+<\/a>/gi
 obj.value=obj.value.replace(reg,'')
}
</script>

<textarea onblur="stripLinks(this)" onkeyup="this.onblur()" cols="40" rows="15"></textarea>
reg=/< *a[^>]+>[^>]+< *\/a *>/gi  

is slightly better
That probably won't stop:

this:

<div style="cursor: pointer; color: blue" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration=''" onclick="location.href='http://kiddanger.com/'">kiddanger.com</div>

or this:

<span style="cursor: pointer; color: blue" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration=''" onclick="location.href='http://kiddanger.com/'">kiddanger.com</span>

or this:

<select name="goaway" onchange="location.href=this.options[this.selectedIndex].value">
<option value="" selected>Where do you want to go today?</option>
<option value="http://microsoft.com/">microsoft</option>
<option value="https://www.experts-exchange.com/">experts exchange</option>
<option value="http://hp.com/">hp</option>
</select>

or this:

<img style="cursor: pointer; border: 5px outset blue" onmouseover="this.style.border='5px inset blue'" onmouseout="this.style.border='5px outset blue'" src="http://i.microsoft.com/h/en-us/r/ms_masthead_ltr.gif" onclick="location.href='http://microsoft.com/'" title="who's your daddy?" />

http://kiddanger.com/lab/ee/talinks.html
That's why I would strip out the http:// parts....

Regards,
Max.
Avatar of DBB

ASKER

Anyone got a quick script that'll strip the entire url?

Thanks

Dbb
ASKER CERTIFIED SOLUTION
Avatar of DreamMaster
DreamMaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DBB

ASKER

can you not strip between <a href> and </a>?
Well..you could...but what if the link is done the way kiddanger described? Then the link is still there...

Regards,
Max.
Avatar of DBB

ASKER

Sorry, just realised that after I posted...
I think this was a good discussion.  I didn't realize the difficulty until I started looking at it.  I don't know why, but I chose a long time ago to just show the text in either <xmp> or <pre></pre> and this renders the links to merely visual.
Avatar of DBB

ASKER

Thanks Kiddanger, your input is much appreciated. As is from everyone else.

Thanks guys

Dbb
Glad to have been helpfull :)

Regards,
Max.
You're welcome, DBB.