Richard Knop
Richard Knop

Reputation: 83745

Open in new window link in an iframe

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>

Upvotes: 1

Views: 14873

Answers (4)

Adnan Ahmad
Adnan Ahmad

Reputation: 896

Try this

window.parent.location = 'http://www.yourSite.com/mypage';

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1075427

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.

Upvotes: 1

Colin
Colin

Reputation: 2502

You could try something like this:

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

Upvotes: 3

dain
dain

Reputation: 6699

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

Upvotes: 1

Related Questions