meta refresh redirect to top frame

2024/2/27 9:01:57

I have the following code:

<title>title of this stuff</title>
<script language="JavaScript"> if (top != self) top.document.title = document.title;
<meta http-equiv="refresh" content="2;'certainpage.html','_top');">
Body of this page

and this doesn't work. I've googled for this and come 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!


Javascript 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"> = 'http://domain.tld/whatever/';

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.location) { = window.location.href; }

And if you would prefer to completely 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.

Related Q&A

How to manipulate the URL with Javascript and JQuery?

I want to make a page with a lot of Javascript interactions. However, while a user navigates through the page the URL must change too. So, when the user shares the URL or saves it, it can lead him to t…

PubNub or Pusher and storing data on my own server

I have a mobile application where users can talk to each others via a chat (user to user only, not chatroom).Today, everything is synchronous. We are considering switching the solution to something mor…

underscore.js: example

I would like to see an example of using underscore.js.In the underscore documentation is written:If youre working with a matrix of nested arrays, zip.apply can transpose the matrix in a sim…

How to change CSS of selected text using Google Chrome Extension

I am making an extension for Chrome browser that uses contextMenus to change CSS of the selected text.But I am not able to access the HTML structure i.e. parentNode of the selected text as I can do ver…

Why does console.log wrongly print an empty array?

I use Firefox.This code logs [].var log = console.log;function new_comb(aComb) {var res = [];log(aComb); // <- This is the linefor (var p in aComb) {var peg = aComb[p];var current = peg[peg.length -…

unterminated string literal error for a django template tag

I have the following snippet of code which gives me unterminated string literal error$(function() {$(#addDropdown).click(function() {var $d = $({{ form |bootstrap }}).fadeIn().delay(1000); $(#dropdow…

Update Image source from AJAX success function

I use to update Label values inside the AJAX success function like below, But I need to know how Im going to apply this method to change/update "src" of an <img id="myimage" src=…

vscode: how to get offset of cursor in the document?

I am working on a vscode extension .. I want to get the cursor position reference to the whole document, for example if Ive the following html: <!DOCTYPE html> <html lang="en"> &l…

JavaScript get permission for Audio.setSinkId

Im trying to change the sinkId at an Audio-Element in a chrome app.Code:var audio = new Audio(); audio.setSinkId("communications");Ill get this error:DOMException: No permission to use reques…

Search for multiple filters in JSON using Javascript forEach and indexOf

I have data in JSON format in which I need to perform search. There are different tags available and when I click on them it searches in JSON and returns the items which has those tags. For this I am u…