how to change the target frame link in jquery?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 09:10:26

问题


i have two frame in my whole website. a frame with navigation bar and another frame with main content. when i click on a link, I want the other frame (content frame) to fade in and out, how would I accomplish this? I tried following jquery code. but it made the navigation frame fade in and out. what i mean is i put this code in the navigation bar frame page, so when i click on navigation bar frame this frame is running the code, so this frame page is fading in or out. how can redirect the content to the another frame? what is the command in jquery to change the target of the link?

$(document).ready(function() {

 $("Body").css("display", "none");

    $("Body").fadeIn(2000);

 $("a").click(function(event){
  event.preventDefault();
  linkLocation = this.href;

  $("Body").fadeOut(2000, redirectPage);  
 });

 function redirectPage() {
  window.location = linkLocation;
 }

});

回答1:


Assuming that you main frame is called frame_main:

For your first question change the context of your body selector, e.g.

$("body", top.frames["frame_main"].document).fadeOut(2000, redirectPage);

And the second question, rather than window.location you have to use top.frames["frameName"].location.

function redirectPage() {
    top.frames["frame_main"].location = linkLocation;
}

Edit: Full example:

$(document).ready(function() {

    var body = $("body", top.frames["frame_main"].document);

    body.css("display", "none").fadeIn(2000);

    $("a").click(function(event){
        event.preventDefault();
        linkLocation = this.href;

        body.fadeOut(2000, redirectPage);  
    });

    function redirectPage() {
        top.frames["frame_main"].location = linkLocation;
    }
});


来源:https://stackoverflow.com/questions/4358660/how-to-change-the-target-frame-link-in-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!