Accessing Computed Styles Cross-Domain
In web development, obtaining computed styles from cross-domain elements can pose a challenge. In this instance, you aim to retrieve the height and width computed styles of an element within an iframe from a different domain.
Approach
To access computed styles in this scenario, consider the following approaches:
window.getComputedStyle() for WebKit Browsers:
You can use it as follows:
window.getComputedStyle(document.getElementById("frameId"), null).getPropertyValue("height");
element.currentStyle for IE:
Example usage:
document.getElementById("frameId").currentStyle.height;
Navigating into iFrame's DOM:
Example
Using the code you provided, here's an example of how to retrieve the height computed style of the HTML element within the iframe using window.getComputedStyle():
window.getComputedStyle(document.getElementById("frameId").contentDocument.documentElement, null).getPropertyValue("height");
Additional Notes
The above is the detailed content of How Can I Access Computed Styles (e.g., Height and Width) of a Cross-Domain IFrame Element?. For more information, please follow other related articles on the PHP Chinese website!