开发者

How do I swap the vertical positions of two frames within a frameset using jQuery.

I have an iframe that I use to display HTML pages published from Excel. This iframe loads a document comprising a frameset, which in turn contains two开发者_如何学Go frames. The bottom frame contains a tabstrip for sheets in the excel document, and I would like to place this at the top rather, where it is immediately visible to users.

My containing iframe:

<iframe name="excel-frame" src="@Url.Content(Model.RelativeHttpPath + "/BettingCards.htm")" width="100%" height="100%"></iframe>

The abridged BettingCards.htm document loaded into the above iframe:

<html>
    <frameset rows="*,39" border=0 width=0 frameborder=no framespacing=0>
        <frame src="bettingcards_files/sheet001.htm" name="frSheet">
        <frame src="bettingcards_files/tabstrip.htm" name="frTabs" marginwidth=0 marginheight=0>
            <noframes>
                <body>
                    <p>This page uses frames, but your browser doesn't support them.</p>
                </body>
        </noframes>
    </frameset>
</html>

I could, if tortured enough, achieve this by manipulating the DOM and rewriting the HTML file, but I would much rather just fire off some jQuery code when the page has loaded.


Try this

$(function(){

 $("iframe[name=excel-frame]").load(function(){
   var iframeContents = $(this).contents();
   iframeContents.find("iframe[name=frTabs]").after(iframeContents.find("iframe[name=frSheet]"));
 });

});


Something like:

$('frameset frame:first').appendTo($('frameset'));

Should do the trick.

Live example: http://jsfiddle.net/ambiguous/ZrxRb/

Warning, I'm using images for the frame content and http://placedog.com/ seems a bit slow tonight.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜