【发布时间】:2012-02-28 21:03:04
【问题描述】:
我在网上找到了一个 java 脚本,如果在索引页面框架之外打开,它会重定向页面。这在所有页面都在主目录中时有效,但是当页面在一个目录上时它不起作用。
当我将位置页面用作:index.html 时,页面是否在新选项卡中打开,它不会重定向。
如果我使用 ../index.html,那么每次我尝试单击指向该页面的链接时,它都会刷新我的索引页面。
有什么想法吗?
<!DOCTYPE html>
<html>
<head>
<script language="javascript">
var framespage="index.html"
if (top.location==document.location)
{
top.location=framespage;
}
else
{
var parent_location=parent.location.href;
var str_beginning=parent_location.length-framespage.length;
if (parent_location.substring(str_beginning, parent_location.length)!=framespage)
{
parent.location=framespage;
}
}
</script>
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head>
</html>
编辑
我发现了一段代码可以完成这项工作。
我的另一个问题是如何延迟加载页面?我想通知用户用户不打算在框架之外加载页面。
如何延迟页面重定向?
<script language="javascript">
if (top.location == self.location)
{
top.location = '../index.html'
}
</script>
【问题讨论】:
-
我只是想知道为什么我被否决并投票赞成:)
标签: javascript html frame