我可以使用
访问<iframe>
中加载的本地内容
$("#frame").contents().find('div').css(...)
当使用<object type="text/html">
代替(同一本地站点)时,内容功能不起作用。
还有其他方式还是我错过了什么?
以下是测试代码:
HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link type="text/css" href="css/style.css" rel="stylesheet"/>
<script type="text/javascript" src="js/jquery-1.3.2-min.js"></script>
<script type="text/javascript" src="js/try.js"></script>
</head>
<body>
<div id="header"></div>
<div id="here_goes_a_proprietary_side_i_dont_want_to_mess_inside">
<object id="frame" type="text/html" data="/nastysite/index.php" width="100%" height="100%"></object>
</div>
<div id="footer"></div>
</body>
JS:
$(document).ready(function() {
alert("go ?"); //temporary solution to wait until everything is loaded.
$("#frame").contents().find('div').css("background-color", "red"); //nothing appens
console.debug($("#frame").contents().find('div')); //nothing
});
答案 0 :(得分:-1)
您的对象标记立即关闭,因此它没有要查找的子div。
<object id="frame" type="text/html" data="/nastysite/index.php" width="100%" height="100%"></object>