meta-tag useful tips – Refresh and Base commands

この記事は約4分で読めます。

We introduce two useful tips using <meta> tag.

How to redirect your web page to another after delay few seconds without JavaScript

When you update your website you need to transfer users accessing to your old url.

You may transfer their access without any JavaScript.

We can use following meta tag for them to introduce and redirect to another new site.

<meta http-equiv=”Refresh” content=”5; URL=http://www.sample.com/index.html“>

  • http-equiv=”Refresh” :  Refreshing access
  • content=”seconds;  : Waiting time to start redirect
  • URL=url or directory to new site” : Url to new site

Here is the source code for the sample above.

<html lang="en">
<head>
 <meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">
 <meta http-equiv="Refresh" content="5; URL=http://www.sample.com/index.html">
<title>new</title>
</head>
<body>
  <h1>You will be redirect to our new top page after 5 seconds</h1>
</body>
</html>

How to apply same “target” to all links in the page

To open links in your web page, “target” is inserted into every <a> tag like <a href = “”  target=”_blank”> .

Instead of frequent usage of the insertion, you may use one of meta tag, <base>.

<base target=”_blank“>

When inserted that tag between <head>  and </head> all of the links in the web page will be opened in new window.

Here is the source code of the sample above.

<html lang="ja">
<head>
  <base target="_blank">
  <title>base</title>
</head>
<body>
  <h1>Open all links in new window</h1>
  <a href="http://www.yahoo.co.jp/">yahoo.co.jp</a><br>
  <a href="http://www.google.co.jp/">google.co.jp</a><br>
  <a href="http://www.bing.com/">bing.com</a><br>
// No need target="_blank" in every <a></a> tag.
</body>
</html>

 

タイトルとURLをコピーしました