简体   繁体   中英

How to provide base64 encoded data url in meta tag

Consider the following HTML :

<html>
    <body>
        <p>Paragraph</p>
        <meta id="meta" http-equiv="refresh">
    </body>
    <script type="text/javascript">  document.getElementById("meta").content="1;url=data:text/html;base64,PFNDUklQVD5hbGVydCgiUHduZWQiKTs8L1NDUklQVD4=";
    </script>
</html>

If you type the data:text/html;base64,PFNDUklQVD5hbGVydCgiUHduZWQiKTs8L1NDUklQVD4= in chrome url address bar. You will get an alert. But it doesnt happen when you use it in the meta tag above. It shows some error - Not allowed to navigate top frame to data URL: data:text/html;base64,PFNDUklQVD5hbGVydCgiUHduZWQiKTs8L1NDUklQVD4=

Mainly i want to auto redirect to a different page. But using the base64 encoded url. If i doThe page does gets redirected to google.com after a second. But when i change the same to content="1;data:text/html;base64,aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbQ==" I get the same error - Not allowed to navigate top frame to data URL Even is you paste the string : data:text/html;base64,aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbQ== in browser address bar it will show you http://www.google.com

I want to do it inside the HTML using javascript or direct. Is there any way to achieve this ?

Thanks

how about using a redirect in javascript like explained here: https://www.w3schools.com/howto/howto_js_redirect_webpage.asp within an onload() function

<html>
<head>
  <!-- ... -->
  <script>
  function myRedirectFunction() {
    // option 1 
    // window.location.href = "http://www.w3schools.com";
    // option 2
    window.location.replace("http://www.w3schools.com");
  }
  </script>
</head>
<body onload="myRedirectFunction()">
   <!-- ... -->
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM