I am aware that drawing canvas onto the same-page that I am working on is doable. But, how can I draw the canvas to "other page"? For example, every time I click a "draw" button, it will create a new HTML page and draw anything on thas new page.
Asked
Active
Viewed 292 times
1
-
Use postMessage... – Jonas Wilms Sep 17 '16 at 10:04
-
How you create a new HTML page, is that embedded as iframe in the same page? – manjs Sep 17 '16 at 10:06
-
1This answer may be helpful: http://stackoverflow.com/questions/19871886/how-to-create-an-html-page-dynamically-in-javascript – smalinux Sep 17 '16 at 10:17
-
@manjs I use window.open() to creat new page – s_m Sep 17 '16 at 10:26
-
@s_m I don't think you can draw it from the parent page, What is the point in draw canvas in another page, or if the information to draw is in the parent page you can pass some parameters through url and extract that from the child (page which is opened using window.open) and draw canvas in windw.onload of child page – manjs Sep 17 '16 at 11:14
1 Answers
0
You could send the data to the other page using postMessage:
button.onclick=function(){
window.open("drawer.html");
window.postMessage("draw","*");
}
Now you have to catch it in the drawer html:
window.addEventListener("message",draw,false);
function draw(){
//draw into canvas
}

Jonas Wilms
- 132,000
- 20
- 149
- 151