bbcode a IE
Napsal: stř 15. pro 2010, 17:09
Ahoj vsem,
nasel jsem script a trosku jsem si ho upravil, ale nefunguje mi v IE. Ostatni prohlizece jsou v pohode. Potreboval bych script doladit, aby byl funkci i pro explorer. Nejsem zrovna guru v javascriptu takze za jakoukoliv radu budu vdecny.
kod pro index.html
<html lang="cs">
<head>
<script type="text/javascript" src="js/js_insert.js"></script>
</head>
<body>
<div id="tu"></div>
<form name="frm" onsubmit="return false">
<a href="#" onClick="bbCode('b', true)">B</a> |
<a href="#" onClick="bbCode('i', true)">I</a> |
<a href="#" onClick="bbCode('u', true)">U</a> |
<br>
<textarea name="text" cols="100" rows="15" tabindex="2"></textarea>
<button onclick="document.getElementById('tu').innerHTML = document.frm.text.value;">POšli</button>
</form>
</body>
</html>
kod pro js_insert.js
var startTag;
var endTag;
var bb;
var inText;
var predText;
var zaText;
var enter;
function bbCode(tag, parovy){
var textarea = document.frm.text;
if (typeof textarea.selectionStart != 'undefined') { //vse mimo IE
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
var stringStart = textarea.selectionStart;
var stringEnd = textarea.selectionEnd;
predText = textarea.value.substring(0,stringStart);
var konec = document.frm.text.value.length;
zaText = textarea.value.substring(stringEnd, konec);
} else if (typeof document.selection != 'undefined') { //IE
var selection = document.selection.createRange().text;
} else {
//alert('Bug!');
}
if(parovy == true){
startTag = '<' + tag + '>';
endTag = '</' + tag + '>';
inText = selection;
bb = predText + startTag + inText + endTag + zaText;
}else if(parovy == false){
startTag = '<' + tag + '>';
endTag = '';
enter = '\n'
textarea.focus();
}
if(tag == 'url'){
if(inText == false){
inText = 'Odkaz';
}else{
inText = selection;
}
startTag = '<a href="http://www.example.com">';
endTag = '</a>';
}
if(tag == 'img'){
if(inText == false){
inText = 'http://www.adresa-obrazku.cz/obrazek.jpg';
}else{
inText = selection;
}
startTag = '<img src="';
endTag = '">';
}
bb = predText + startTag + inText + endTag + zaText;
document.frm.text.value = bb;
}
nasel jsem script a trosku jsem si ho upravil, ale nefunguje mi v IE. Ostatni prohlizece jsou v pohode. Potreboval bych script doladit, aby byl funkci i pro explorer. Nejsem zrovna guru v javascriptu takze za jakoukoliv radu budu vdecny.
kod pro index.html
<html lang="cs">
<head>
<script type="text/javascript" src="js/js_insert.js"></script>
</head>
<body>
<div id="tu"></div>
<form name="frm" onsubmit="return false">
<a href="#" onClick="bbCode('b', true)">B</a> |
<a href="#" onClick="bbCode('i', true)">I</a> |
<a href="#" onClick="bbCode('u', true)">U</a> |
<br>
<textarea name="text" cols="100" rows="15" tabindex="2"></textarea>
<button onclick="document.getElementById('tu').innerHTML = document.frm.text.value;">POšli</button>
</form>
</body>
</html>
kod pro js_insert.js
var startTag;
var endTag;
var bb;
var inText;
var predText;
var zaText;
var enter;
function bbCode(tag, parovy){
var textarea = document.frm.text;
if (typeof textarea.selectionStart != 'undefined') { //vse mimo IE
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
var stringStart = textarea.selectionStart;
var stringEnd = textarea.selectionEnd;
predText = textarea.value.substring(0,stringStart);
var konec = document.frm.text.value.length;
zaText = textarea.value.substring(stringEnd, konec);
} else if (typeof document.selection != 'undefined') { //IE
var selection = document.selection.createRange().text;
} else {
//alert('Bug!');
}
if(parovy == true){
startTag = '<' + tag + '>';
endTag = '</' + tag + '>';
inText = selection;
bb = predText + startTag + inText + endTag + zaText;
}else if(parovy == false){
startTag = '<' + tag + '>';
endTag = '';
enter = '\n'
textarea.focus();
}
if(tag == 'url'){
if(inText == false){
inText = 'Odkaz';
}else{
inText = selection;
}
startTag = '<a href="http://www.example.com">';
endTag = '</a>';
}
if(tag == 'img'){
if(inText == false){
inText = 'http://www.adresa-obrazku.cz/obrazek.jpg';
}else{
inText = selection;
}
startTag = '<img src="';
endTag = '">';
}
bb = predText + startTag + inText + endTag + zaText;
document.frm.text.value = bb;
}