- Сообщения
- 8,671
- Репутация
- 2,481
Хочу прикрутить на форуме функцию копирования выделенного кода, но возникли некие проблемы.
Нужна помощь js знатоков.
Внимание вопрос...
Имеем код:
вызывается так:
почему этот код выдаёт следующую ошибку:
?
Нужна помощь js знатоков.
Внимание вопрос...
Имеем код:
JavaScript:
function smfCopySelection(codeElement)
{
// create an element to contain our copying flash element
if(!document.getElementById('clipboard')) {
var copydiv = document.createElement('div');
copydiv.id = 'clipboard';
document.body.appendChild(copydiv);
}
// clear our element ready for new stuff to copy
document.getElementById('clipboard').innerHTML = '';
smfSelectText(codeElement);
// input = the stuff in the code tag
var input = window.getSelection();
// replace active line breaks with carriage returns
input = input.replace(/<(BR\/|br\/|BR \/|br \/|br|BR)>/g, '\r\n');
// remove active html (part of smf)
input = input.replace(/<\/?[^>]+(>|$)/g, '');
// now decode our content (which maybe html itself) (added by the user)
var output = input.replace(/</g,"<").replace(/>/g,">").replace(/ /g," ").replace(/&/g, '&').replace(/"/g, '"');
// using a flash file to copy to clipboard
document.getElementById('clipboard').innerHTML = '<embed src="clipboard.swf" FlashVars="clipboard='+encodeURIComponent(output)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
}
вызывается так:
JavaScript:
<a href="javascript:void(0);" onclick="smfCopySelection(this);" class="codeoperation">Копировать</a>
почему этот код выдаёт следующую ошибку:
Uncaught exception: TypeError: 'input.replace' is not a function
?