简体   繁体   中英

How do I open a div in a separate pop up window (as opposed to a lightbox modal window)

I have a hidden div in my page. I was wondering if there is a way to open it up in a separate window as opposed to a lightbox within the same page. There are a lot of ways to do this the lightbox method, but can't seem to find a way to do it in a separate window. I am running jQuery on the page

Lets assume this is the div:

<style>
    #hidden {
        visibility: hidden;
    }

</style>

<div id="hidden">
    <p>I am a hidden div</p>
    <p>Hopefully i'll open up in a new window</p>
</div>

I tried the following method in jQuery, but it just ended up opening the same page

$(".button").click(function(){
            window.open('#yeah');
        });

You can use document.write to set the contents on your popup window:

var w = window.open();
w.document.write( $("#hidden").html() );
w.document.close(); //finish "loading" the page

That's because you're using window.open incorrectly.

See here: https://developer.mozilla.org/en/DOM/window.open

var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openRequestedPopup()
{
  windowObjectReference = window.open("http://www.cnn.com/", "CNN_WindowName", strWindowFeatures);
}

Have a look at the documentation. window.ope n expects an url.

It is a javascript not an jQuery function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM