怎样点击链接,跳转到另外一个页面,并且指定iframe 的内容
问题描述:
A页面包含ifreme,点击链接显示不同的内容
<ul >
<li><a id="mee1" href="web/cp01.html" target="mainFrame">工厂需求</a></li>
<li><a href="web/cp02.html" target="mainFrame">分公司/总代需求</a></li>
<li><a href="web/cp03.html" target="mainFrame">门店需求</a></li>
</ul>
<iframe src="web/cp01.html" width="100%"; height="200px" frameborder="0" scrolling="no" name="mainFrame" id="external-frame" onload="setIframeHeight(this)" ></iframe></iframe>
因为导航是通用的,里面有三级目录,想在首页或者其他页面打开这个A页面的同时,调用ifram里面不同的内容,应该怎么写?
答
在打开A页面的url地址中加个参数 a.html?iframe=web/cp01.html
在A页面中获取这个参数,并设置iframe的src。
var ors = window.location.search.match(/(?:\?|&)iframe=([^&]+)/);
if (ors) {
document.getElementById("iframeID").src = ors[1];
}
答
一个a对应一个ifame吧,name名字应该要不同。