function selImg(text){
document.frames["SendMsg"].focus();
var range =document.frames["SendMsg"].document.selection.createRange();
alert(range); ==>这样在Chrome浏览器里不行,应该怎么修改才对啊?
}
document.frames["SendMsg"].focus();
var range =document.frames["SendMsg"].document.selection.createRange();
alert(range); ==>这样在Chrome浏览器里不行,应该怎么修改才对啊?
}
要用window.getSelection ()
<head>
<script type="text/javascript">
function TestSelection () {
if (window.getSelection) { // all browsers, except IE before version 9
var selectionRange = window.getSelection ();
alert ("The text content of the selection:\n" + selectionRange.toString ());
}
else {
if (document.selection.type == 'None') {
alert ("No content is selected, or the selected content is not available!");
}
else {
var textRange = document.selection.createRange ();
alert ("The text content of the selection:\n" + textRange.text);
}
}
}
</script>
</head>
<body>
Select some text or <button>element</button>, or do not select anything, before you click on the button below.
<br /><br />
<button onclick="TestSelection ();">Test the selection!</button>
</body>
是不是我的这行代码
var range =document.frames["SendMsg"].document.selection.createRange();
要改成
var range =document.frames["SendMsg"].window.getSelection ();