Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript document.getSelection().toString()始终为&引用;在ie中使用iframe时_Javascript_Html - Fatal编程技术网

Javascript document.getSelection().toString()始终为&引用;在ie中使用iframe时

Javascript document.getSelection().toString()始终为&引用;在ie中使用iframe时,javascript,html,Javascript,Html,我想在MouseUp上获取所选文本 我也试过了 setTimeout(()=>{ var selectedData=contentWrapper.getSelection().toString(); 警报(选定数据) }, 1008) html代码 <iframe src="url"></iframe> 这样,它在IE、Chrome和FF(在本地测试)中工作,但我无法在这里触摸iframe 函数showSelection(){ var selectedData=do

我想在MouseUp上获取所选文本

我也试过了

setTimeout(()=>{
var selectedData=contentWrapper.getSelection().toString();
警报(选定数据)
}, 1008)
html代码

<iframe src="url"></iframe>

这样,它在IE、Chrome和FF(在本地测试)中工作,但我无法在这里触摸iframe

函数showSelection(){
var selectedData=document.getSelection().toString();
警报(选定数据)
}
var-contentWrapper;
函数attachIF(){
如果(location.href==”https://stacksnippets.net/js)返回;
var ifr=document.createElement(“iframe”);
ifr.src=“javascript:”+//访问被拒绝。请访问stackoverflow.com
“window.onload=函数(){”+
“document.write(\\'if(document.domain)document.domain=\\\”“+document.domain+”\\\\”;”+
“document.write(\”“+parent.document.body.innerText+”“”)+
"\\');"+
“document.close();”+
“parent.contentWrapper=文档;”+
“document.body.onmouseup=parent.CheckSelections;”+
"};'";
文件.正文.附件(ifr);
}
函数CheckSelections(){
var selectedData=contentWrapper.getSelection().toString();
警报(选定数据)
}

要选择的某些文本。

如果iframe使用的域与您的域不同,您将面临一些同源策略问题。是的,但在这种情况下,它会抛出一些错误,如权限被拒绝。但是在这里,我可以通过contentWrapper.getSelection().getRangeAt(0.startContainer.textContent)获取内容,但是contentWrapper.getSelection().toString()总是显示为空字符串,即“没有要测试的IE,但是您能确认您可以用它重现此问题吗?”?还有,有什么变化吗?getSelection()是一个函数,在使用结果之前不检查它返回什么,始终检查函数返回值。