-
-
Save fasiha/c07cdbfbf636873497ec to your computer and use it in GitHub Desktop.
How to use iframes in Anki, potentially to do kanji character handwriting recognition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{cloze:Text}} | |
<br> | |
{{type:cloze:Text}} | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<button id="grab-button" onclick="sendMessageToGetSelection();">Grab selection from iframe</button> | |
<iframe id="my-iframe" width="800" height="90" src="http://localhost:8888/target.html"></iframe> | |
<script> | |
window.addEventListener("message", receiveMessage, false); | |
function receiveMessage(event) { | |
d3.select('body').append('div').text(function() {return "received event!: " + event.data;}); | |
document.getElementById('typeans').value = event.data; | |
} | |
function sendMessageToGetSelection() { | |
var iframe= document.getElementById('my-iframe'); | |
var iwin= iframe.contentWindow || iframe.contentDocument.defaultView; | |
iwin.postMessage('gimme selection plz', '*'); | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
</head> | |
<body> | |
<script> | |
window.addEventListener("message", receiveMessage, false); | |
function receiveMessage(event) { | |
var resp = '' + window.getSelection(); | |
d3.select('body').append('div').text("Got message from " + event.origin + ". Sending: " + resp); | |
event.source.postMessage(resp, '*'); | |
} | |
</script> | |
<h1>Some kanji follows</h1> | |
<div>一二三四五六七八九十口日月田目古吾冒朋明唱晶品呂昌早旭世胃旦胆亘凹凸旧自白百中千舌升昇丸寸肘専博占上下卓朝嘲只貝唄貞員貼見児元頁頑凡負万句肌旬勺的首乙乱直具真工左右有賄貢項刀刃切召昭則副別丁町可頂子孔了女好如母貫兄呪克小少大多夕汐外名石肖硝砕砂妬削光太器臭嗅妙省厚奇川州順水 | |
</div> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment