target="_top" emulation using JavaScript
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>
精彩评论