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

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

programmeradmin4浏览0评论

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');
        });

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');
        });
Share Improve this question asked Dec 7, 2011 at 13:11 SeedorfSeedorf 6753 gold badges13 silver badges28 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

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/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./", "CNN_WindowName", strWindowFeatures);
}

Have a look at the documentation. window.open expects an url.

It is a javascript not an jQuery function.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论