Note that there are some explanatory texts on larger screens.

plurals
  1. POgetSelection from iframe with bookmarklet
    primarykey
    data
    text
    <p>I'm trying to make a bookmarklet that does something with the selected text on any given website, but I'm having trouble when the selected text is in an iframe.</p> <p>The bookmarklet link looks like:</p> <pre><code>&lt;a id="bookmarklet" href="javascript:(function(){if(window.myBookmarklet!==undefined) {myBookmarklet();} else{document.body.appendChild(document.createElement('script')).src='http://www.mywebsite.com/bookmarklet.js?';}})(); "&gt;Bookmarklet&lt;/a&gt; </code></pre> <p>And bookmarklet.js looks like:</p> <pre><code>(function(){ var v = "1.3.2"; if (window.jQuery === undefined || window.jQuery.fn.jquery &lt; v) { var done = false; var script = document.createElement("script"); script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js"; script.onload = script.onreadystatechange = function(){ if (!done &amp;&amp; (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { done = true; initBookmarklet(); } }; document.getElementsByTagName("head")[0].appendChild(script); } else { initBookmarklet(); } function initBookmarklet() { (window.myBookmarklet = function() { if($('iframe').length &gt; 0) { $('iframe').each(function(){ var iframe = $(this).get(0); var win= iframe.contentWindow? iframe.contentWindow : iframe.contentDocument.defaultView; alert (win.getSelection().toString()); }); } })(); } })(); </code></pre> <p>I tested a few things - I can definitely get the frame object, and return its html, but getSelection just returns empty.</p> <p>Is it a cross domain thing, because my bookmarklet.js is somewhere else? </p> <p>UPDATE: For reference, the page I am specifically trying this on is this one: <a href="http://cases.iclr.co.uk/Subscr/search.aspx?path=WLR%20Dailies/WLRD%202011/wlrd2012-246" rel="nofollow">http://cases.iclr.co.uk/Subscr/search.aspx?path=WLR%20Dailies/WLRD%202011/wlrd2012-246</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload