【发布时间】:2012-03-01 12:00:09
【问题描述】:
我将任何不在框架中的页面重定向到 index.html。索引正在更改为 index.html?page.html
我想使用地址中的附加部分并将帧的 SRC 设置为该值。
我不知道如何正确包含location.search.substring(1),以免导致错误。
每个站点都有代码:
if (top.location == self.location)
{
top.location = 'index.html?' + location.href.replace(/^.*[\\\/]/, '');
}
索引页包含在
之后<frameset rows="100px,100%" cols="*" border="0">
<frame src="logo.html" name="logo" scrolling="no">
<frameset rows="*" cols="200,100%" border="0">
<frame src="menu.html" name="menu" scrolling="no">
<script language="javascript">
if (location.search && location.search.length > 1 && location.search.charAt(0) == "?")
{
document.write('<frame src="' + location.search.substring(1) + '" name="page" scrolling="auto">');
}
else
{
document.write('<frame src="main_page.html" name="page" scrolling="auto">');
}
</script>
</frameset>
</frameset>
这个想法是从我之前的question得到的。
顺便说一句。我应该这样做吗?有没有更好的解决方案?
【问题讨论】:
-
location是每一帧中的一个全局对象 (window-object)。它应该被称为:top.window.location或window.location。location本身并不代表页面的当前 URL,如果尚未重定向,则可以从名为href的属性中找到该 URL。href也用于更改页面的URL。 -
@Teemu,我明白你在说什么,但我不知道如何让它发挥作用。
标签: javascript html frames