There may be an easier way to do this. But this is what I came up with. Theoretically, it should work:
So, to clear the selection, this is one way:
var clearSelection = function(){
if (window.getSelection) {
if (window.getSelection().empty) {
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) {
window.getSelection().removeAllRanges();
}
} else if (document.selection) {
document.selection.empty();
}
}
source: Clear text selection using JavaScript
iframe, , , iframe - .
iframes, .
Iframe , :
document.addEventListener("click", function(){
window.postMessage({
"source": "iframe1"
}, "*");
})
document.addEventListener("click", function(){
window.postMessage({
"source": "iframe2"
}, "*");
})
:
var childrenFrames = window.parent.frames;
window.onmessage = function(e){
if (e.data.source === "iframe1") {
childrenFrames[1].postMessage("clearSelection", "*");
}
if (e.data.source === "iframe2") {
childrenFrames[0].postMessage("clearSelection", "*");
}
};
iframes, window.top.frames ( ) window.parent.frames ( , )
[: iFrame sibling]
"clearSelection" :
window.onmessage = function(e){
if(e.data === "clearSelection"){
clearSelection();
}
}
, , , . .