Alex Chen
Alex Chen

Reputation: 63

Open iframe in a new window

How do I open an iframe in a new window? I tried with "scrolling='auto'". It did not work.

I put my code here:

<iframe width="572px" scrolling="auto" height="335px" 
        frameborder="1" src="http://XXXX.com/iframe-page"
        style="border: 0px none #ffffff;" name="national-campaign" 
        marginheight="0px" marginwidth="0px">
</iframe>

I want to open a link in a new window. I have two sites, a corporate site and a dealer site. On the corporate site, I have a page with only an image that I want to display in both corporate site and dealer site. When you click on the image, it goes to view detail page. However, what I want in my dealer site is, when you click on the iframe image, it opens the tab in a new window, instead of displaying detail page inside the iframe.

Any ideas? Cheers.

Upvotes: 4

Views: 66751

Answers (4)

Kamuran S&#246;necek
Kamuran S&#246;necek

Reputation: 3334

You can do it with jquery and window.open method.

HTML:

<iframe id="iframe" width="572px" scrolling="auto" height="335px" 
        frameborder="1" src="http://XXXX.com/iframe-page"
        style="border: 0px none #ffffff;" name="national-campaign" 
        marginheight="0px" marginwidth="0px">
</iframe>

JS :

var iframe = $("#iframe"); 
var newWindow = window.open(iframe.attr(src), 'Dynamic Popup', 'height=' + iframe.height() + ', width=' + iframe.width() + 'scrollbars=auto, resizable=no, location=no, status=no');
newWindow.document.write(iframe[0].outerHTML);
newWindow.document.close();
iframe[0].outerHTML = ''; // to remove iframe in page.

Upvotes: 6

Alessandro Incarnati
Alessandro Incarnati

Reputation: 7248

Try to add target="_top" inside that link.

or alternatively if you need to open a new page from a link inside an iframe if i understood correctly you can:

Using jQuery:

$('iframe a').attr('target', '_blank');

Upvotes: 2

Christophe
Christophe

Reputation: 28114

The easy way is to use a hyperlink with an attribute target="_blank".

If the height and width are important to you (cf. your example), then you can use the JavaScript method window.open.

Upvotes: 1

kosherjellyfish
kosherjellyfish

Reputation: 373

I would recommend that you just use a hyperlink to another page rather than an iframe. Or a screenshot image that is actually a link.

Some users may be 'smart' enough to right-click within the iframe (in internet explorer) and select a 'open in new window' option, but others wouldn't do that.

Upvotes: 0

Related Questions