HaloScan Commenting and Trackback

roltrtrocl

Inserting HTML

Premium Members Only

The following code will place HTML links in your comment window.
People can either highlight code and hit the link to place the tags around the words, or just click on the link.

Place this in between your <head> </head> tags
<script language="javascript1.2" type="text/javascript">
// Startup variables
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie  = ((clientPC.indexOf("msie") != -1)       && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1)      && (clientPC.indexOf('spoofer')==-1)
          && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
          && (clientPC.indexOf('webtv')==-1)        && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

function addlink()
{
 var txtarea = document.addComment.addMessage;

 txtarea.focus();

 if ((clientVer >= 4) && is_ie && is_win)
 {
  theSelection = document.selection.createRange().text; // Get text selection
  if (theSelection)
  {
   // Add tags around selection
   var linkurl = prompt('Enter the complete link for the webpage', 'http://');
   if(linkurl == null) return;
   document.selection.createRange().text = '<a href="' + linkurl + '">' + theSelection + '</a>';
   txtarea.focus();
   theSelection = '';
   return;
  }
 }
 else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
 {
  var linkurl = prompt('Enter the complete link for the webpage', 'http://');
  if(linkurl == null) return;
  start_tag = '<a href="' + linkurl + '">';
  end_tag   = '</a>';
  mozWrap(txtarea, start_tag, end_tag);
  return;
 }
  var linkurl   = prompt('Enter the complete link for the webpage', 'http://');
 if(linkurl == null) return;
 var linktitle = prompt('Enter the title of the webpage', '');
 if(linktitle == null) return;
 txtarea.value += '<a href="' + linkurl + '">' + linktitle + '</a>';
 txtarea.focus();
 return;
}

function addtag(input_tag)
{
 var txtarea = document.addComment.addMessage;

 txtarea.focus();
 theSelection = false;
 start_tag = '<' + input_tag + '>';
 end_tag   = '</' + input_tag + '>';

 if ((clientVer >= 4) && is_ie && is_win)
 {
  theSelection = document.selection.createRange().text; // Get text selection
  if (theSelection)
  {
   // Add tags around selection
   document.selection.createRange().text = start_tag + theSelection + end_tag;
   txtarea.focus();
   theSelection = '';
   return;
  }
 }
 else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
 {
  mozWrap(txtarea, start_tag, end_tag);
  return;
 }
 txtarea.value += start_tag + end_tag;
 txtarea.focus();
 return;
}

// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
 var selLength = txtarea.textLength;
 var selStart = txtarea.selectionStart;
 var selEnd = txtarea.selectionEnd;
 if (selEnd == 1 || selEnd == 2) selEnd = selLength;
 var s1 = (txtarea.value).substring(0,selStart);
 var s2 = (txtarea.value).substring(selStart, selEnd)
 var s3 = (txtarea.value).substring(selEnd, selLength);
 txtarea.value = s1 + open + s2 + close + s3;
 return;
}
</script>

and this above the textbox or wherever you want
<a href="javascript:addtag('b')" title="<b>" target="_self"><b>Bold</b></a>
<a href="javascript:addtag('i')" title="<i>" target="_self"><i>Italic</i></a>
<a href="javascript:addtag('blockquote')" title="<blockquote>" target="_self">"Quote"</a>
<a href="javascript:addlink()" title="<a>" target="_self">Link</a>
<br />

of course there's nothing stopping you from changing the text, or adding images.
Page was generated in 0.2919 seconds