开发者

Applying styles to the content in an iframe

The page inside iframe is loaded dynamically by javascript.

I use jQuery, so I tried like this.

var css2 = '<link rel="stylesheet" href="/inc/css/style.css" type="text/css"/>';
$("iframe").contents().find("head").append(css2);

This works fine with firefox, but not with IE.

Then I created dom and append it to the head tag manually with 'createElement', 'setAttribute'. It still does not work with IE.

I think there is a security issue in controlling iframe dynamically. Is there a way to make开发者_C百科 it work with IE?


try this (untested):

var id = '#myIframeId'
var iframe = document.frames ? document.frames[id] : document.getElementById(id);
var ifWin = iframe.contentWindow || iframe;


$(ifWin).find('head').append(css2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜