We help IT Professionals succeed at work.

Need help with HTML Editor for insert hyperlink and Emailto functions in asp.net

coolSri
coolSri asked
on
1,238 Views
Last Modified: 2012-08-14
Hi,

I have an Html editor which has both insert hyperlink and emailto features. Using them I can insert links and email, but the links for both are not visible until I click submit.t I need someway for them to remeber the link inserted for the selected text before submitting the form. My script for insertign hyperlink and email is as follows
function AddLink(){
             var myUrl = prompt("Please enter a URL:", "http://");
             myUrl="javascript:void window.open('"+myUrl+"');"
               if (myUrl != null && myUrl != "http://") {
                 getIFrameDocument("ifrHTML").execCommand("createLink", false, myUrl);
              document.getElementById('ifrHTML').contentWindow.focus();
             
              }

      function AddMail(){
                   prompt("Please enter a URL:", "mailto://");
                   if(myUrl != null && myUrl != "mailto://")
                   {
                 var newLink = getIFrameDocument("ifrHTML").execCommand("createLink");
             document.getElementById('ifrHTML').contentWindow.focus();
             }
                             
            }

Can anyone please suggest a way to view the link behind the text before the form is submited.

Your help will be greatly appreciated. Ia m including my whole code for html editor

Thanks,
Sri.
<script language="javascript" type="text/javascript">
   
		    function getIFrameDocument(aID)
		    {
              // if contentDocument exists, W3C compliant (Mozilla)
              if (document.getElementById(aID).contentDocument){
                return document.getElementById(aID).contentDocument;
              } else {
                // IE
                return document.frames[aID].document;
              }
            }
            function getIFrame(aID)
            {
             // if contentDocument exists, W3C compliant (Mozilla)
              if (document.getElementById(aID)){
                return document.getElementById(aID);
              } else {
                // IE
                return document.frames[aID];
              }
            } 
			function setButtonBar()
			{
				if(getIFrameDocument('ifrHTML').queryCommandState('Bold') == true)
					button_over(document.getElementById('bold'));
				else
					button_out(document.getElementById('bold'));
				
				if(getIFrameDocument('ifrHTML').queryCommandState('Italic') == true)
					button_over(document.getElementById('italic'));
				else
					button_out(document.getElementById('italic'));
					
				if(getIFrameDocument('ifrHTML').queryCommandState('Underline') == true)
					button_over(document.getElementById('underline'));
				else
					button_out(document.getElementById('underline'));
				
				if(getIFrameDocument('ifrHTML').queryCommandState('InsertUnorderedlist') == true)
					button_over(document.getElementById('bullets'));
				else
					button_out(document.getElementById('bullets'));
					
				if(getIFrameDocument('ifrHTML').queryCommandState('Insertorderedlist') == true)
					button_over(document.getElementById('numberedlist'));
				else
					button_out(document.getElementById('numberedlist'));
				
				if(getIFrameDocument('ifrHTML').queryCommandState('Superscript') == true)
					button_over(document.getElementById('superscript'));
				else
					button_out(document.getElementById('superscript'));
				
				if(getIFrameDocument('ifrHTML').queryCommandState('Subscript') == true)
					button_over(document.getElementById('subscript'));
				else
					button_out(document.getElementById('subscript'));
					
				if(getIFrameDocument('ifrHTML').queryCommandState('JustifyRight') == true)
					button_over(document.getElementById('rightjustify'));
				else
					button_out(document.getElementById('rightjustify'));
				
				if(getIFrameDocument('ifrHTML').queryCommandState('JustifyLeft') == true)
					button_over(document.getElementById('leftjustify'));
				else
					button_out(document.getElementById('leftjustify'));
				
				if(getIFrameDocument('ifrHTML').queryCommandState('JustifyCenter') == true)
					button_over(document.getElementById('centerjustify'));
				else
					button_out(document.getElementById('centerjustify'));
			}
 
			function turnOn()
			{
				//ifrHTML.document.designMode = 'On';
				getIFrameDocument('ifrHTML').contentWindow.onkeyup = setButtonBar;
				getIFrameDocument('ifrHTML').contentWindow.onmouseup = setButtonBar;
				getIFrame('ifrHTML').contentWindow.focus();
			}
 
			function mnuClick(command, aArg)
			{
				getIFrameDocument('ifrHTML').execCommand(command, false, aArg);
				getIFrame('ifrHTML').contentWindow.focus();
			}
 
			function setFontStyle()
			{
			    getIFrameDocument('ifrHTML').execCommand('FontName', false, "Arial");
			    getIFrameDocument('ifrHTML').execCommand('FontSize', false, "2");
			    getIFrameDocument('ifrHTML').execCommand("ForeColor",false,"#3a3a3a");
			    getIFrame('ifrHTML').contentWindow.focus();
			}
			
			function button_over(button)
			{
				button.src = '../images/HTMLEditor/' + button.id + '_over.gif';
			}
			
			function button_out(button)
			{
				button.src = '../images/HTMLEditor/' + button.id + '.gif';
			}
 
			function AddLink(){
             var myUrl = prompt("Please enter a URL:", "http://");
             myUrl="javascript:void window.open('"+myUrl+"');"
	         if (myUrl != null && myUrl != "http://") {
		     getIFrameDocument("ifrHTML").execCommand("createLink", false, myUrl);
              document.getElementById('ifrHTML').contentWindow.focus();
             
              }
             
            } 
            
                       
            function view()
            {
            document.getElementById("ifrHTML").value;
            }
                       
			function AddMail(){
			 prompt("Please enter a URL:", "mailto://");
			 if(myUrl != null && myUrl != "mailto://")
			 {
		     var newLink = getIFrameDocument("ifrHTML").execCommand("createLink");
             document.getElementById('ifrHTML').contentWindow.focus();
             } 
                              
            }           
               
            
			function alignImage(alignType)
			{
				var selectRange = getIFrameDocument('ifrHTML').selection.createRange();
				for (i = 0; i < selectRange.length; i++)
					if (selectRange(i).tagName == "IMG")
						selectRange(i).align=alignType;
			}
			
		</script>
		<TABLE id="Table1" cellSpacing="0" cellPadding="3" width="100%" border="0">
			<TR>
				<TD style="BORDER-RIGHT: lightgrey 1px solid; BORDER-TOP: lightgrey 1px solid; BORDER-LEFT: lightgrey 1px solid; BORDER-BOTTOM: lightgrey 1px solid"
					background="../images/HTMLEditor/buttonbar_bg.gif" height="30"><IMG id="bold" onmouseover="button_over(this);" onclick="mnuClick('Bold');" onmouseout="button_out(this);"
						alt="Bold" src="../images/HTMLEditor/bold.gif"> <IMG id="italic" onmouseover="button_over(this);" onclick="mnuClick('Italic');" onmouseout="button_out(this);"
						alt="Italic" src="../images/HTMLEditor/italic.gif"> <IMG id="underline" onmouseover="button_over(this);" onclick="mnuClick('Underline');"
						onmouseout="button_out(this);" alt="Underline" src="../images/HTMLEditor/underline.gif">&nbsp;
					<IMG alt="" src="../images/HTMLEditor/sep.gif"> <IMG id="Copy" onmouseover="button_over(this);" onclick="mnuClick('Copy');"
						onmouseout="button_out(this);" alt="Copy" src="../images/HTMLEditor/Copy.gif">
					<IMG id="Paste" onmouseover="button_over(this);" onclick="mnuClick('Paste');"
						onmouseout="button_out(this);" alt="Paste" src="../images/HTMLEditor/Paste.gif">
					<IMG alt="" src="../images/HTMLEditor/sep.gif"> <IMG id="bullets" onmouseover="button_over(this);" onclick="mnuClick('insertunorderedlist');"
						onmouseout="button_out(this);" alt="Bullets" src="../images/HTMLEditor/bullets.gif">
					<IMG id="numberedlist" onmouseover="button_over(this);" onclick="mnuClick('insertorderedlist');"
						onmouseout="button_out(this);" alt="Numbering" src="../images/HTMLEditor/numberedlist.gif">
					<IMG alt="" src="../images/HTMLEditor/sep.gif"><U> <IMG id="indent" onmouseover="button_over(this);" onclick="mnuClick('indent');" onmouseout="button_out(this);"
							alt="Increase Indent" src="../images/HTMLEditor/indent.gif"></U> <IMG id="outdent" onmouseover="button_over(this);" onclick="mnuClick('outdent');" onmouseout="button_out(this);"
						alt="Decrease Indent" src="../images/HTMLEditor/outdent.gif"> <IMG alt="" src="../images/HTMLEditor/sep.gif">
					<IMG id="leftjustify" onmouseover="button_over(this);" onclick="mnuClick('JustifyLeft');"
						onmouseout="button_out(this);" alt="Align Left" src="../images/HTMLEditor/leftjustify.gif">
					<IMG id="rightjustify" onmouseover="button_over(this);" onclick="mnuClick('JustifyRight');"
						onmouseout="button_out(this);" alt="Align Right" src="../images/HTMLEditor/rightjustify.gif">
					<IMG id="centerjustify" onmouseover="button_over(this);" onclick="mnuClick('JustifyCenter');"
						onmouseout="button_out(this);" alt="Center" src="../images/HTMLEditor/centerjustify.gif">
					<IMG alt="" src="../images/HTMLEditor/sep.gif"> <IMG id="subscript" onmouseover="button_over(this);" onclick="mnuClick('Subscript');"
						onmouseout="button_out(this);" alt="Subscript" src="../images/HTMLEditor/subscript.gif">
					<IMG id="superscript" onmouseover="button_over(this);" onclick="mnuClick('Superscript');"
						onmouseout="button_out(this);" alt="Superscript" src="../images/HTMLEditor/superscript.gif">
					<IMG alt="" src="../images/HTMLEditor/sep.gif"> <IMG id="link" onmouseover="button_over(this);" onclick="AddLink();"  onfocus="selected(this);"onmouseout="button_out(this);"
						alt="Insert Hyperlink" src="../images/HTMLEditor/link.gif">&nbsp;<IMG id="mail" onmouseover="button_over(this);" onclick="AddMail();" onfocus="view();" onmouseout="button_out(this);"
										alt="Insert Mailto" src="../images/HTMLEditor/mail.gif">&nbsp; <IMG alt="" src="../images/HTMLEditor/sep.gif">
				    <IMG id="setStyle" onmouseover="button_over(this);" onmouseout="button_out(this);" onclick="setFontStyle();"
						alt="Set the seleted texts to be the default font style" src="../images/HTMLEditor/setStyle.gif">
				</TD>
			</TR>
			<TR>
				<TD style="BORDER-RIGHT: lightgrey 1px solid; BORDER-TOP: lightgrey 1px solid; BORDER-LEFT: lightgrey 1px solid; BORDER-BOTTOM: lightgrey 1px solid"><IFRAME id="ifrHTML" frameBorder="no" width="100%" height="200" runat="server" enableviewstate="false"></IFRAME>
				</TD>
			</TR>
    </TABLE>

Open in new window

Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hey thanks alot for the links. :)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.