问题
I have a problem with loading data into an < object > using Javascript. It refuses to work in Chrome, no error message either.
You can see a minimal example to play with here: http://tinkerbin.com/HIqG0ypb
回答1:
It is strange to me that browsers assume object.data could be set as URI but display content available at that URI. It sounds like a security flaw : full content could be injected into a page without using frame. I wonder if test.com in your example has access to window.parent or something like that
[EDIT]
So
<script type="text/javascript">
function openFrame() {
document.getElementById('testFrame').data="http://test.com";
}
</script>
Must be written for Chrome as :
<script type="text/javascript">
function openFrame() {
document.getElementById('testFrame').data="http://test.com";
var el = document.getElementById("testFrame");
var h = el.innerHTML;
el.innerHTML = h;
}
</script>
where testFrame is :
<object id="testFrame" type="text/html" style="overflow-x: hidden; width: 100%; height: 100%" />
来源:https://stackoverflow.com/questions/11245385/object-works-in-every-browser-except-google-chrome