rain13 Posted February 26, 2011 Share Posted February 26, 2011 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 More sharing options...
[dx] Posted February 26, 2011 Share Posted February 26, 2011 Read this:http://w3schools.invisionzone.com/index.ph...c=29928&hl=I tryed same. But why, if it has already.. Link to comment Share on other sites More sharing options...
rain13 Posted February 26, 2011 Author Share Posted February 26, 2011 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 More sharing options...
birbal Posted February 26, 2011 Share Posted February 26, 2011 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 More sharing options...
rain13 Posted February 26, 2011 Author Share Posted February 26, 2011 How to hack this thing so that it would allow me to insert php code? Link to comment Share on other sites More sharing options...
Starfall Posted February 27, 2011 Share Posted February 27, 2011 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 More sharing options...
rain13 Posted February 27, 2011 Author Share Posted February 27, 2011 no I meant I want edit that thing so that i could use it to post php, but since it's too buggy I'll have to write my own editor. Link to comment Share on other sites More sharing options...
rain13 Posted February 27, 2011 Author Share Posted February 27, 2011 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 More sharing options...
rain13 Posted February 28, 2011 Author Share Posted February 28, 2011 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 More sharing options...
rain13 Posted March 2, 2011 Author Share Posted March 2, 2011 anyone got ideas about my last post? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.