meta refresh redirect to top frame

后端 未结 1 1703
北海茫月
北海茫月 2021-01-19 02:02

I have the following code:



title of this stuff


        
相关标签:
1条回答
  • 2021-01-19 02:35

    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">
        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 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.

    0 讨论(0)
提交回复
热议问题