Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open iframe in a new window

Tags:

html

iframe

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.

like image 921
Alex Chen Avatar asked Nov 02 '25 18:11

Alex Chen


1 Answers

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.
like image 147
Kamuran Sönecek Avatar answered Nov 05 '25 16:11

Kamuran Sönecek