Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Access Elements in FancyBox iframe

There is an iframe, opened in fancybox window.
The content of the iframe is external.
Is there a way to access this content and to change the style of one of the elements?

like image 696
lvil Avatar asked Dec 29 '25 06:12

lvil


2 Answers

Since the iframe has contents from the same domain, access the iframe using contents() like this:

$('#fancybox-content iframe').contents().find('.selector')
like image 194
Mottie Avatar answered Dec 30 '25 19:12

Mottie


If the iFrame is on another domain you can't access it in any way due to browser restriction. This is called same origin policy.

One thing that can get around it is the greasmonkey extension for firefox (this has no actual utility, it's just to let you know this fact if you are interested)

like image 43
Nicola Peluchetti Avatar answered Dec 30 '25 20:12

Nicola Peluchetti