I have a very simple WYSIWYG editor using contenteditable. It works fine, but I want to check if the selected text is used as a link. When I use document.queryCommandState ('CreateLink'), it always returns false, even if the text is within the bounds. An example is below.
Am I doing this wrong or is there another way to check if the text is used as a link?
<script>
function testLink () {
var state = document.queryCommandState('CreateLink');
alert(state);
document.execCommand ('CreateLink', false, 'http://www.example.com');
}
</script>
<div contenteditable="true">Here is some sample text to test with.</div>
<br /><br />
<button onclick="testLink();">Test the state of the create link command</button>
Frank source
share