Jump to content

Need hlp with simple WYSIWYG editor


rain13

Recommended Posts

I am trying to make my own WYSIWYG editor. it works fine but is it possible to make it work so that instead of adding b tags around selected text it wold make that text bold in that text box?.?

<script type="text/javascript">function blah() {   var ta = document.getElementById("test");   if (document.selection) {	  str = document.selection.createRange().text	  document.selection.createRange().text = "<B>" + str + "</B>";	  return true;   }   else if (ta.selectionStart) {	  var startPos = ta.selectionStart;	  var endPos = ta.selectionEnd;	  var str = ta.value.substring(startPos, endPos);	  ta.value = ta.value.substring(0, startPos) + "<B>" + str + "</B>" + ta.value.substring(endPos, ta.value.length);	  return true;   }   else {	  return false;   }}</script><input type="button" value="Bold" onclick="blah()" /><br /><textarea id="test" style="height:150px">This is a test to see if the bold tags will work.</textarea>

Link to comment
Share on other sites

Read this:http://w3schools.invisionzone.com/index.ph...c=29928&hl=I tryed same. But why, if it has already..
That's cool. after year I would have ended up with something like that.I wonder if its hard to add button for youtube there.And how do I load html contents into this when I start editing my page and how do I write data from this editor to html file after i finish?
Link to comment
Share on other sites

And how do I load html contents into this when I start editing my page and how do I write data from this editor to html file after i finish?
you will need some server side languages to load the data into the textarea and after editing it saving it to database or file
Link to comment
Share on other sites

Huh??It is impossible to hack a system if you use PHP to hack. In other words, "PHP Injection" does not exist.If you are looking for information on how to create and use PHP scripts, check the PHP tutorial of W3Schools and the official PHP site: php.net.

Link to comment
Share on other sites

Current editor uses Editor.execCommand to make that text bold.I want to change that editor so that instead of executing command 'bold' it would wrap my custom text around selection.Is there any way to rewrite that js so that when I press on button B it would wrap my own text around selection?editor.html

<html>	<head>	<title>Simple Javascript WYSIWYG Editor</title>		<script language="Javascript" src="editor.js"></script>	</head>	<body>		<form method="POST">			<div>				<input type="button" onclick="Format('bold')" value="B" />				<br/>				<iframe id="textbox" style="width:800px; height:200px"></iframe><br/>				<input type="submit" value="Go" />				<input type="hidden" id="text" name="text" />			</div>		</form>	</body></html>

editor.js

var Editor;function Format(action){	Editor.execCommand(action, false, null);}function Colour(colour){	Editor.execCommand("forecolor",false, colour);}window.onload = function(){	Editor = document.getElementById('textbox').contentWindow.document;	Editor.designMode = "on";	document.forms[0].onsubmit = function()	{		var text = document.getElementById('text');		text.value = Editor.body.innerHTML;	}}

Link to comment
Share on other sites

I tried to invent code, but it doesnt work. How to modify this code so that Bold button would work?

<script type="text/javascript">function blah() {   var ta = document.getElementById("test");   if (document.selection) {	  str = document.selection.createRange().text	  document.selection.createRange().text = "<B>" + str + "</B>";	  return true;   }   else if (ta.selectionStart) {	  var startPos = ta.selectionStart;	  var endPos = ta.selectionEnd;	  var str = ta.value.substring(startPos, endPos);	  ta.value = ta.value.substring(0, startPos) + "<B>" + str + "</B>" + ta.value.substring(endPos, ta.value.length);	  return true;   }   else {	  return false;   }}window.onload = function(){	Editor = document.getElementById('test').contentWindow.document;	Editor.designMode = "on";	document.forms[0].onsubmit = function()	{		var text = document.getElementById('text');		text.value = Editor.body.innerHTML;	}}</script><input type="button" value="Bold" onclick="blah()" /><br /><iframe id="test" style="width:800px; height:200px">This is a test to see if the bold tags will work.</iframe>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...