Seeking advice on how to obtain the background color of an element located on a different webpage within the same domain. My current approach involves loading the external page into an iframe, but I believe there must be a more efficient method that someone can guide me towards.
Current Approach
To start, I embed the external page within an iframe:
var $page = $('<iframe/>').attr('src', 'http://mydomain.com/page');
I then add this iframe to my existing page:
$('#iframe-placeholder').append($page);
Finally, I retrieve the CSS property:
$('iframe').load(function(){
var backgroundColor = $(this).contents().find('#my-element').css('backgroundColor');
});
Limitations of Current Method
- It's slow
- It's asynchronous
- It's not entirely effective as it always returns
transparent
.
Query
Is there a synchronous way to access the CSS property of the external page? Ideally, I would prefer to avoid loading the entire page into an iframe as it seems excessive. Any insights or recommendations would be greatly appreciated...