最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open in new window link in an iframe - Stack Overflow

programmeradmin0浏览0评论

I have an iframe on a page and there is a link (on the same domain) I would like to open in a new physical window. When I use target="_blank", it just reloads the page in an iframe with the new one.

I also tried this JavaScript/jQuery code:

$(document).ready(function() {
    $('a[target=_blank]').click(function() {
        window.open(this.href);
        return false;
    })
});

With no success.

The HTML tag looks like this:

<a class="blue" href="/page/terms-of-service" target="_blank">Terms of Service</a>

I have an iframe on a page and there is a link (on the same domain) I would like to open in a new physical window. When I use target="_blank", it just reloads the page in an iframe with the new one.

I also tried this JavaScript/jQuery code:

$(document).ready(function() {
    $('a[target=_blank]').click(function() {
        window.open(this.href);
        return false;
    })
});

With no success.

The HTML tag looks like this:

<a class="blue" href="/page/terms-of-service" target="_blank">Terms of Service</a>
Share Improve this question edited Jun 15, 2013 at 20:56 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Sep 21, 2009 at 22:50 Richard KnopRichard Knop 83.8k154 gold badges398 silver badges561 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 3

You could try something like this:

$(function() {
    $(window).load(function() {
        $('iframe').contents().find('body a.blue').click(function() {
            window.open(this.href);
            return false;
        });
    });
});

Try putting <base target="_blank" /> into the <head> tag of the iframe page.

If your link really looks like this:

<a href="blah" target="_blank">some text</a>

...then barring something very unusual, any conforming browser will open the linked page in a new window (or new tab, on tabbed browsers with the "new window = new tab" feature turned on). If that's not happening, there's something specific to your page that's interfering with the normal process. If you post the actual link markup, we may be able to help you.

Try this

window.parent.location = 'http://www.yourSite./mypage';
发布评论

评论列表(0)

  1. 暂无评论