I have the following code:
<html>
<head>
<title>title of this stuff</title>
<script language="JavaScript">
if (top != self) top.document.title = document.title;
</script>
<meta http-equiv="refresh" content="2; URL=javascript:window.open('certainpage.html','_top');">
</head>
<body>
Body of this page
</body>
</html>
and this doesn't work. I've googled for this and e to the same conclusion everywhere: this should work. But it doesn't. Can anyone help me out why this page isn't: 1. refreshing as long as I have the javascript in there (and yes, js is enabled in my browser) 2. refreshing to the new page in the top frame
Any help would be appreciated!
I have the following code:
<html>
<head>
<title>title of this stuff</title>
<script language="JavaScript">
if (top != self) top.document.title = document.title;
</script>
<meta http-equiv="refresh" content="2; URL=javascript:window.open('certainpage.html','_top');">
</head>
<body>
Body of this page
</body>
</html>
and this doesn't work. I've googled for this and e to the same conclusion everywhere: this should work. But it doesn't. Can anyone help me out why this page isn't: 1. refreshing as long as I have the javascript in there (and yes, js is enabled in my browser) 2. refreshing to the new page in the top frame
Any help would be appreciated!
Share Improve this question edited Jul 31, 2012 at 14:39 user1093284 asked Jul 27, 2012 at 14:50 MalachiMalachi 9776 gold badges16 silver badges32 bronze badges 3- 2 possible duplicate of Using Javascript to override or disable meta refresh tag – Diodeus - James MacFarlane Commented Jul 27, 2012 at 14:52
- @Billy Moat: Yes. I'm running a script in frame A, while the frame B shows me the progress (with meta refresh) until done. Then it should change the meta refresh so it'll refresh to the parent frame. – Malachi Commented Jul 27, 2012 at 16:08
- @Diodeus: "possible duplicate".. funny. However, thank you for your reply, because the window.location javascript thing on the page you linked to (turned into window.top.location) did the trick! (had to put some script in to make this only happen when a condition was met) – Malachi Commented Jul 27, 2012 at 16:17
1 Answer
Reset to default 13Javascript won't work in the refresh meta tag like that.
As you're using javascript anyway, keep it simple like this:
<script type="text/javascript">
window.top.location = 'http://domain.tld/whatever/';
</script>
But there's also a better (because smarter) way to do it. This doesn't require you to hard-code the URL for each page. It checks if the page is topmost and if not, if calls the page's URL to the top:
<script type="text/javascript">
if(window.top.location != window.location)
{
window.top.location.href = window.location.href;
}
</script>
And if you would prefer to pletely avoid using javascript (which some users will have disabled), there's also an even simpler way to do it. Add the following to your head section and all links on that page will open "topmost":
<base target="_top">
All you have to do is to choose one of these three options. All of them should get you going just fine.