Created
November 7, 2019 16:11
-
-
Save calebklc/6b36707ea4989d238b569c1865933a5f to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>data</title> | |
</head> | |
<body> | |
<iframe | |
id="data-transferer" | |
style="border: 0;width: 100%;height: 100%;" | |
src="http://localhost:3000/" | |
onload="frameLoaded()" | |
></iframe> | |
<script> | |
function frameLoaded() { | |
var childFrame = document.getElementById('data-transferer'); | |
childFrame.contentWindow.postMessage('asdasd', '*'); | |
} | |
</script> | |
</body> | |
</html> |
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
import React, { Component } from 'react'; | |
import Cookies from 'js-cookie' | |
class FormDataTransferer extends Component { | |
// https://juejin.im/post/5bac7801e51d450e9649ef7d | |
receiveData = (e) => { | |
if(e != null) { | |
console.log(e.data); | |
var tt = document.getElementById('tt'); | |
tt.textContent = e.data; | |
// NOTE: e.data should include | |
// NOTE: formType / link, base64 string | |
// TODO: chunk base64 string and store to cookie | |
// TODO: redirect to the form / link | |
} | |
} | |
componentDidMount() { | |
window.addEventListener( | |
'message', | |
this.receiveData, | |
false | |
); | |
} | |
componentWillUnmount() { | |
window.removeEventListener('message', this.receiveData) | |
} | |
render() { | |
return ( | |
<div> | |
Loading... | |
</div> | |
); | |
} | |
} | |
export default FormDataTransferer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment