Problem:
Accessing the computed height and width values of an element from a cross-domain iframe can be challenging, particularly if you're not able to access the iframe's content directly.
Solution:
Using Browser-Specific Functions:
Applying to Cross-Domain Content:
To retrieve computed styles from cross-domain content, you can use window.getComputedStyle in modern browsers or element.currentStyle in IE. However, these functions only work on elements within the current document, so you need to navigate into the iframe's DOM before using them.
Example (WebKit):
window.getComputedStyle(document.getElementById("frameId"), null).getPropertyValue("height")
Native jQuery Function:
Alternatively, you can use jQuery's .height() function, which simplifies the process:
$('#frameId').height();
Additional Notes:
The above is the detailed content of How Can I Get Computed Styles from a Cross-Domain Iframe?. For more information, please follow other related articles on the PHP Chinese website!