Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to import external stylesheet and javascript into an iframe

Tags:

jquery

css

iframe

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" />')`
like image 477
matthewb Avatar asked Jan 22 '13 11:01

matthewb


People also ask

Can you put JavaScript in an iframe?

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.

Can I add CSS to iframe?

We can use inline CSS for the iframe by using CSS inside the iframe tag.

Can you style content in an iframe?

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.)


1 Answers

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)

like image 135
codelove Avatar answered Sep 21 '22 13:09

codelove