Answered by:
Calling WinRT component from an iframe?

Question
-
Hello, now I need to invoke a winRT component written in C++ in an iframe because it needs to run some external scripts. I have read the article
http://msdn.microsoft.com/en-us/library/windows/apps/hh441569%28v=VS.85%29.aspx , however it seems I can't activate the component if it's in the iframe.
in default.html
<iframe id="mapFrame" src="ms-wwa-web:///map.html">
and in the js file included in map.html,
var a= new mydll.func(); //error, mydll undefined
Is there some way to do this not in default.js?
Monday, November 28, 2011 12:41 AM
Answers
-
Hi Yi,
I am trying to create a simple repro of the problem now. Are both the html file and the js file in your application, or is one of them an externally fetched resource? Also are you familiar with this whitepaper: http://www.microsoft.com/download/en/details.aspx?id=27408 ?
You must use ms-wwa:/// to ensure you are in a local context. If you are using ms-wwa-web:/// you cannot access WinRT or WinMD components.
-Jeff
Jeff Sanders (MSFT)- Edited by Jeff SandersMicrosoft employee, Moderator Wednesday, November 30, 2011 12:50 PM consolidate answer
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, November 30, 2011 12:50 PM
- Marked as answer by Jie Bao Wednesday, December 7, 2011 7:39 AM
Tuesday, November 29, 2011 4:19 PMModerator -
Yes, both html and js are in same app.
default.html
<iframe id="mapFrame" src="ms-wwa-web:///map.html?"> </iframe>and in mapFrame.js which included in iframe "map.html"
var v = new WinRTComponentDll.dll1; //error
It looks you can't call this component like what we do in default.js. Now I use "postMessage" as workaround to post result to iframe.
Friday, December 2, 2011 1:37 AM -
Hi Yi,
You can definitely call into WinRT from an iframe as I discussed in my previous reply. You MUST use a local context however. I am happy you have a workaround!
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, December 2, 2011 12:50 PM
- Marked as answer by Jie Bao Wednesday, December 7, 2011 7:39 AM
Friday, December 2, 2011 12:50 PMModerator
All replies
-
Hi Yi,
I am trying to create a simple repro of the problem now. Are both the html file and the js file in your application, or is one of them an externally fetched resource? Also are you familiar with this whitepaper: http://www.microsoft.com/download/en/details.aspx?id=27408 ?
You must use ms-wwa:/// to ensure you are in a local context. If you are using ms-wwa-web:/// you cannot access WinRT or WinMD components.
-Jeff
Jeff Sanders (MSFT)- Edited by Jeff SandersMicrosoft employee, Moderator Wednesday, November 30, 2011 12:50 PM consolidate answer
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, November 30, 2011 12:50 PM
- Marked as answer by Jie Bao Wednesday, December 7, 2011 7:39 AM
Tuesday, November 29, 2011 4:19 PMModerator -
Yes, both html and js are in same app.
default.html
<iframe id="mapFrame" src="ms-wwa-web:///map.html?"> </iframe>and in mapFrame.js which included in iframe "map.html"
var v = new WinRTComponentDll.dll1; //error
It looks you can't call this component like what we do in default.js. Now I use "postMessage" as workaround to post result to iframe.
Friday, December 2, 2011 1:37 AM -
Hi Yi,
You can definitely call into WinRT from an iframe as I discussed in my previous reply. You MUST use a local context however. I am happy you have a workaround!
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, December 2, 2011 12:50 PM
- Marked as answer by Jie Bao Wednesday, December 7, 2011 7:39 AM
Friday, December 2, 2011 12:50 PMModerator