title: getSelection is not working for an image in Chrome
body: <p>In my site I am using a WYSIWYG editor that uses an iframe.</p>
  
  <p>When I select a text with double click in order to add a link to it, in Chrome, Safari and Firefox the selected text is the right one and the link is added.</p>
  
  <p>However, when I click an image instead, the selection is done only in Firefox. Chrome and Safari have an empty selection and in order to select the image and add a link on it, I have to drag the mouse over it, like a manual select.</p>
  
  <p>My code is:</p>
  
  <pre><code> var sel = parent.document.getElementById('myframe').contentWindow.document.getSelection();
  
   if (sel.rangeCount &gt; 0) {
      var range = sel.getRangeAt (0);
      var docFragment = range.cloneContents ();
      var tmpDiv = document.createElement ("div");
      tmpDiv.appendChild (docFragment);
      selHTML = tmpDiv.innerHTML;
   }
  
   if (selHTML != '') {
       parent.document.getElementById('myframe').contentWindow.document.execCommand(id,false,value);
   }
  </code></pre>
  
  <p>Is there any way to solve this problem?</p>
  
  <p>Thanks in advance.</p>
  
  <p>I change the code to that one according to @Tim suggestions:</p>
  
  <pre><code> var iframeWin = parent.document.getElementById('myframe').contentWindow;
   var iframeDoc = iframeWin.document;
   var sel = iframeWin.getSelection();
   var range = iframeDoc.createRange();
   var referenceNode = document.getElementsByTagName("img").item(0);
   range.selectNode(referenceNode);
  
   sel.removeAllRanges();
   sel.addRange(range);
  parent.document.getElementById('myframe').contentWindow.document.execCommand(id,false,value);
  </code></pre>
  
  <p>But still not works. Any more suggestions?</p>