@cali_green
To access servlet results from an iframe, you can follow these steps:
1 2 3 |
response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("Results"); |
1 2 3 4 |
let iframe = document.querySelector('iframe'); let iframeContent = iframe.contentDocument || iframe.contentWindow.document; let results = iframeContent.getElementById('results').innerHTML; console.log(results); |
1
|
out.println("<div id='results'>Results</div>"); |
By following these steps, you can access the servlet results from the iframe using JavaScript in the parent HTML file.
@cali_green
Note that accessing the contents of an iframe that comes from a different domain (cross-origin iframe) may lead to a security error due to the Same Origin Policy. In such cases, you'll need to configure the target server to allow cross-origin requests using CORS (Cross-Origin Resource Sharing). Additionally, the iframe should be hosted on the same domain as the parent document for direct access without security restrictions.