javascript 如何在单独的弹出窗口中打开 div(与灯箱模式窗口相反)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8415856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I open a div in a separate pop up window (as opposed to a lightbox modal window)
提问by Seedorf
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
我的页面中有一个隐藏的 div。我想知道是否有办法在单独的窗口中打开它而不是同一页面中的灯箱。有很多方法可以使用lightbox方法来执行此操作,但似乎无法在单独的窗口中找到一种方法。我在页面上运行 jQuery
Lets assume this is the div:
让我们假设这是 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
我在 jQuery 中尝试了以下方法,但它最终打开了同一页面
$(".button").click(function(){
window.open('#yeah');
});
回答by hugomg
You can use document.write to set the contents on your popup window:
您可以使用 document.write 在弹出窗口中设置内容:
var w = window.open();
w.document.write( $("#hidden").html() );
w.document.close(); //finish "loading" the page
回答by Trevor
That's because you're using window.open incorrectly.
那是因为您错误地使用了 window.open。
See here: https://developer.mozilla.org/en/DOM/window.open
请参阅此处: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);
}
回答by PiTheNumber
Have a look at the documentation. window.open expects an url.
看看文档。window.open 需要一个 url。
It is a javascript not an jQuery function.
它是一个 javascript 而不是 jQuery 函数。