Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- waitForIframeAndPrintContent(function(content) {
- s_widget.setFieldValue('description_html', content)
- });
- function waitForIframeAndPrintContent(callback) {
- var container = document.querySelector('.description_html');
- if (!container) {
- console.error('Container not found');
- return;
- }
- // Function to check and extract iframe content
- function checkAndExtractIframeContent() {
- var iframe = container.querySelector('iframe');
- if (iframe && iframe.contentWindow.document.body) {
- try {
- var content = iframe.contentWindow.document.body.innerHTML;
- console.log('Iframe content:', content);
- callback(content); // Call the callback function with the content
- } catch (error) {
- console.error('Error accessing iframe content:', error);
- }
- } else {
- console.error('Iframe not found');
- }
- }
- // Creating an observer to watch for DOM changes
- var observer = new MutationObserver(function(mutations, obs) {
- var iframe = container.querySelector('iframe');
- if (iframe && iframe.contentWindow.document.body) {
- checkAndExtractIframeContent();
- obs.disconnect(); // Stop observing once the iframe is processed
- }
- });
- // Observer configuration
- var config = { childList: true, subtree: true };
- // Start observing
- observer.observe(container, config);
- // Also check once directly in case the iframe is already there
- checkAndExtractIframeContent();
- }
- // Example usage:
- waitForIframeAndPrintContent(function(content) {
- // You can use the content here
- console.log('Received iframe content:', content);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement