Jump to content


Javascript URL/Hyperlink inserter?


2 replies to this topic

#1 Chris.

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male

Posted 13 May 2007 - 06:16 PM

I was wondering how to make the thing that uses javascript to insert a url with BBCode. Like the thing on IPB when you make a post, and click the insert hyperlink button, it pops up that textarea thing, then you type in the url, and then you click okay, then you type in what you want the link to look like. If you click the insert hyperlink button (Posted Image) while making a post, you will notice what I mean.

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 13 May 2007 - 09:36 PM

If you have a normal BBCode JavaScript snippet for inserting the code into the textfield that is already set up, then its simple.

function bbcodelink(txtarea){
	var my_link = prompt('Enter URL:', 'http://');
	if(my_link == null) return false;
	if(my_link.length < 6){
		alert('This URL is not valid!');
		return false;
	}
	return bbcode(txtarea, '[url='+my_link+']', '[/url]');
}

Quick Example:

<textarea id="comment" name="comment"></textarea><br /><a href="java script:void(0);" onclick="bbcodelink('comment');" title="Add Link"><img src="/images/link.png" alt="" /></a>


#3 Chris.

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male

Posted 13 May 2007 - 10:05 PM

Thanks for that.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users