2011-11-17 134 views
3

我想在有两个iframe的情况下创建内容页面。一个iframe是一个带按钮或链接的浮动sidemenu,而另一个iframe实际上包含内容。我希望用户能够点击sidemenu上的链接,如“图片”,然后让该链接更改其他iframe的内容。我还希望鼠标悬停在菜单上的每个标签(图像,家庭,阅读)的整个单元都会改变颜色。从另一个iframe中的链接加载iframe中的页面

我已经尝试了很多事情,但这里是代码的基础:

<html> 
<head> 
<title>Main Content Page</title> 
</head> 
<body background="background.jpg"> 
<table> 
<th> 
    <iframe src="sidebar.html" frameborder="no" border="0" scrolling="no" height="750" width="450"></iframe> 
<th> 
    <iframe id ="content" src="" frameborder="no" border="0" scrolling="no" width="600" height="800"></iframe> 
</table> 
</body> 
</html> 

,然后为内容的iframe无关紧要的页面。侧边栏的代码是:

<html> 
<head> 
<title>Main</title> 
<base target="content"> 
<style type="text/css"> 
body{bgcolor: black;} 
a{color: white} 
a:link, a:visited{background-color: black} 
<!--a:hover{background-color: gray}--> 
<!--td:hover{background-color: gray}--> 
buttons:hover{background-color: gray} 

td, th{border:1px solid black; background-color:black;} 
table{border:1px solid gray;} 
td {font-family: Kunstler Script; color: white; font-size: 72; padding:15px;} 
</style> 
</head> 
<body> 
<table align="center"> 
    <tr><div class="buttons"><div><td onclick="target.content.home.href='html'">Home</div> 
    <tr><div><td onclick="target.content.href='images.html'">Images</div> 
    <tr><div><td onclick="target.content.href='readings.html'">Readings</div></div> 
</table> 

</div> 
</body> 
</html> 

眼下链接不工作,但按键就变色

+0

那么,不要这样做,使用CSS固定位置http:// jsfi ddle.net/HerrSerker/fC2Zf/ – HerrSerker

回答

4

添加name属性内容的iframe

<iframe name="content" src="" frameborder="no" border="0" scrolling="no" width="600" height="800"></iframe> 

更改onclick事件到

parent.window.frames['content'].location = 'url' 

对于一个工作示例创建3 p年龄。

main.html中含有

<iframe src="./1.html"></iframe> 
<iframe name="content"></iframe> 

1.HTML含有

<a href="#" onclick="parent.window.frames['content'].location = './2.html'">load</a> 

2.HTML含有

iframe 2 loaded 

加载main.html后,您会看到第一个带有加载链接的iframe加载1.html,单击第一个iframe中的加载链接,然后将2.html加载到其他内容iframe中。

0
  • 您有2个iframe。正确?
  • 举一个名称值你的第二IFRAME:

    <iframe name="iframe2" src="content.html"></iframe> 
    
  • 添加 “目标” 属性对您的第一个iframe的链接代码靶向你的第二iframe的ID:

    <a href="something.html" target="iframe2">Link Here!</a> 
    

我是一个初学者我自己,并希望理解你的问题是正确的:)

相关问题