开发者

target="_top" emulation using JavaScript

开发者 https://www.devze.com 2022-12-25 01:08 出处:网络
Suppose we have frameset of with 2 frames, one frame is kind a tiny horizontal header and second is kind of \"content\" frame with 3rd-party html page inside. When user clicks on some link inside \"co

Suppose we have frameset of with 2 frames, one frame is kind a tiny horizontal header and second is kind of "content" frame with 3rd-party html page inside. When user clicks on some link inside "content" frame, the whole page (frameset) should be reloaded with this link, the same behavior if "content" frame has "target=_top" a开发者_StackOverflowttribute. How to do this using JS?

The main problem here is - that I can't edit html of "content" page.


Try setting window.location to the target URL.


Here is my quick solution:

<html>
<head>
<script type="text/javascript">
    function load(){
        // set target="_top" to reload whole frame
        var links = this.content.document.getElementsByTagName("a");
        for(var i = 0; i < links.length; i++){
            var link = links[i];
            link.target="_top";
        }
    }
</script>
</head>

<frameset rows="50,*" frameborder="0" onload="load()">
   <frame src="/header.html" scrolling="no">
   <frame src="/content.html" name="content">
</frameset> 

</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消