- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2019 12:05 PM
Hi there,
I am using an iframe in Service portal widget to load page from another application. I have a requirement to use window.postMessage() to post a message from the widget (client script) to the child window. From the client script I tried to access the content window using $window.frames[index].contentWindow but it does not seem to work.
Can someone please suggest me how to achieve this?
Thanks in advance,
Vinu
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2019 12:21 PM
I'd recommend you to use $window.document.querySelector or $window.document.getElementById or $window.document.querySelectorAll to query iframe element, which content you need to access. For example, if your custom Service Portal page has only one iframe, you can use $window.document.querySelector("iframe").contentWindow to access the contentWindow. Alternatively, angular.element("iframe")[0].contentWindow should work too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2019 12:21 PM
I'd recommend you to use $window.document.querySelector or $window.document.getElementById or $window.document.querySelectorAll to query iframe element, which content you need to access. For example, if your custom Service Portal page has only one iframe, you can use $window.document.querySelector("iframe").contentWindow to access the contentWindow. Alternatively, angular.element("iframe")[0].contentWindow should work too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2019 01:12 PM
Hi Oleg,
Than you for your quick response but unfortunately these steps do not seem to work.
My client script start like the below
function($scope, $window) {
....................
...................
}
Inside the script I tried to access the iframe window like below
a) $window.document.querySelector("iframe") gives null
b) angular.element("iframe")[0].contentWindow throws error as angular.element("iframe") gives null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2019 12:28 PM
Hi Oleg,
My bad, please ignore my response above. I am able to access the Iframe using the steps you mentioned above.
Thank you so much,
Vinu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2019 01:43 PM
You are welcome!
