I just want to import an external stylesheet and a js into an iframe's head tag. Is it possible ?
i have tried in the html head a custom jquery function `
$(this).contents().find('head').append('<link href="http://mywebsite.com/css/iframe.css?" rel="stylesheet" type="text/css" />')`
Either your src-url will be used or your code between the iframe-tags will be used; never both. This means that there is no way to "embed a javascript into an iframe". The only way to get your script in there would be to add it to the source page that you're loading into the iframe.
We can use inline CSS for the iframe by using CSS inside the iframe tag.
When you have access to the code inside an iFrame, you can manipulate its DOM that can lead to style changes. This is a more specific (and perhaps more useful) case built from my base article on communicating with an iFrame. (That article has some base content, but it's not required to understand this article.)
The window object in the iframe is the property of the page that was loaded into the iframe. THE ONLY WAY for the containing page to manipulate the iframe’s window object is if the domain of the containing page and the iframe page are the same. (due to the cross-domain restriction policy)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With