how to include css and javascript in iFrame

2019-08-12 09:14发布

问题:

My css and javascript aren't taken into consideration in iframes. For example I've this iframe :

<iframe name="richTextField" id="richTextField"/>

Where I inject a .css file after page load:

$(document).ready(iFrameOn);

function iFrameOn() {
    richTextField.document.designMode = "On";
    richTextField.document.head.innerHTML = '<link rel="stylesheet" type="text/css" href="iframe.css">';
}

In chrome the head of my iframe will contain my stylesheet but it won't have any effect, in ie it's not even included.

Anyway I noticed that alert doesn't work for me on jsfiddle while it works for other users. Take this code for instance. No alert dialog appears for me on chrome. I think this might be linked. Any idea why this would happen ?