在我的索引页面上有两个用于登录和注册的链接以及一个iframe
我已经分别设计了两个(登录和注册)页面现在我想强制这两个页面被打开只在iframe,而不是在一个单独的选项卡,如果有人试图直接访问重定向到索引页。这是我的代码。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href="login.php" target="frame">Login</a> <a href="signup.php">Signup</a>
<iframe src="" name="frame" frameborder="0"></iframe>
</body>
</html>
发布于 2018-07-23 02:03:45
我找到了用Javascript做这件事的最好方法..
var myUrl = 'http://localhost/test/index.php';
if(window.top.location.href !== myUrl) {
window.top.location.href = myUrl;
}
发布于 2018-07-23 01:27:34
您可以将以下内容添加到HTMl文档的head
中,使其在未加载到iframe中时自动重定向:
<script>
window.onload = function(){
if (top === self) {
//not inside iframe
location = 'url';
}
}
</script>
JSFiddle:http://jsfiddle.net/xjqyrsd7/
https://stackoverflow.com/questions/51467368
复制相似问题