我有一个如下的html文档。我想从ifame html documet内的文档中更改“ title iframe”的某些属性。但是我无法从titleFrame iframe内的我的title.php代码更改iframe属性。我该怎么办这个?
<style>
iframe
{
width: 100%;
border: 0;
}
#titleFrame
{
position: absolute;
height: 100%;
top: 0;
left: 0;
background-color: red;
}
</style>
<body>
<div class='myDiv'> </div>
<img class='myImg' src='image.jpg' />
<iframe src="src/title.php" id="titleFrame" name="titleFrame" scrolling="No" noresize="noresize" title="title" />
<iframe src="" id="mainFrame" name="mainFrame" scrolling="Auto" title="mainFrame" />
</body>
里面的src / title.php文件:
<div class="titleDiv">
<span class='titleText'> Resource Management </span>
<span id='userNameDisp'> </span>
<input id='theTime' type=text value='' size=35 />
</div>
<?php
if(session_id() == '')
session_start();
if(isset($_SESSION['userName']))
{
echo "<script> ";
echo "$(\"#userNameDisp\").html(\"Welcome \"+\"".$_SESSION['userName']."<br/><span class='logOutClass'><a href='logout.php' target='mainFrame'> Logout </a> </span>\"); ";
echo "window.parent.document.getElementById('titleFrame').css('height','70px'); ";
echo "$('#titleFrame').css('background-color','#EFEFEF'); ";
echo "window.parent.document.getElementById('mainFrame').setAttribute('src','src/home.php'); ";
echo "</script></body> </html>";
return;
}
?>
最佳答案
以下javascript代码可用于更改父iframe属性。
echo "window.parent.document.getElementById('titleFrame').style.height='70px'; ";
关于javascript - HTML:根据特定iframe本身中存在的文档设置iframe属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24993991/