如何在 JavaScript 中创建 DOM 窗口?
我有一个聊天室应用程序。我正在使用以下代码进行私人聊天。我正在使用 window.open
函数,但大多数浏览器弹出窗口都被阻止,所以我想使用 DOM WINDOWS 而不是 Windows,有人可以告诉我如何做到这一点吗?
<script language="javascript">
<!--
function popUp(URL) {
var Win = window.open(URL, '<?php echo $got_request['id'];?>', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=530,left=212,top=134');
}
popUp("../private.php?s=<?php echo $got_request['username'];?>&room=<?php echo $got_request['roomname'];?>");
// -->
</script>
I have a chatroom application. I am using following code for private chat. I am using window.open
function but by most of browser popup is getting blocked so I want to use DOM WINDOWS instead of windows, can anybody tell me how I can do that?
<script language="javascript">
<!--
function popUp(URL) {
var Win = window.open(URL, '<?php echo $got_request['id'];?>', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=530,left=212,top=134');
}
popUp("../private.php?s=<?php echo $got_request['username'];?>&room=<?php echo $got_request['roomname'];?>");
// -->
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个名为 DOM Window 的 jQuery 插件可以帮助您实现您想要的目标。
实际上,不存在 DOM 窗口这样的东西,它纯粹是页面的一部分,其样式看起来像一个新窗口。无论如何,这个插件可能就是您正在寻找的。
http://swip.codylindley.com/DOMWindowDemo.html
根据您的要求,很可能您'我想将 DOM 窗口与(我敢说)iframe 一起使用。
There's a jQuery plugin called DOM Window that can help you acheive what you want.
Realistically there's no such thing as a DOM Window, it's purely a part of the page that's styled to look like a new window. Anyhow, this plugin may be what you're looking for.
http://swip.codylindley.com/DOMWindowDemo.html
Given your requirements, it's likely you'll want to use the DOM Window with an (dare I say it) iframe.
我认为您所说的“DOM 窗口”只是页面上的一个元素,通常是一个
div
。您可以通过多种方式将其放置在页面上您喜欢的任何位置,包括绝对定位。(编辑:天哪,我错过了您的帖子上有一个
jquery-ajax
标记,这表明您正在使用 jQuery。下面的内容可能是啊,嗯……)有很多库可以为您制作此类轻量级窗口。常用术语是“灯箱”或“对话框”。对于 jQuery(现在我已经看到了该标签),您可以查看 jQuery UI,它有这个以及很多其他方便的东西。
以下是如何执行此操作的示例(实时复制):
HTML:
CSS:
JavaScript:
这并不意味着最重要的,最终的(根本),只是为了给你指明正确的方向。
一些参考:
createElement
、appendChild
、parentNode
、removeChild
我在上面使用的东西A "DOM window" in the sense I think you mean is just an element on the page, frequently a
div
. You can position it anywhere on the page you like in a variety of ways, including absolute positioning.(Edit: Blast, I missed that you had a
jquery-ajax
tag on your post, which suggests to me that you're using jQuery. The below could have been a lot shorter. Ah, well...)There are lots of libraries out there to do these sorts of lightweight windows for you. The usual terms are "lightbox" or "dialog". For jQuery (now that I've seen the tag), you might look at jQuery UI, which has this and a lot of other handy things.
Here's an example of how you can do that (live copy):
HTML:
CSS:
JavaScript:
That's not meant to be the be-all, end-all (at all), just to point you in the right direction.
Some references:
createElement
,appendChild
,parentNode
,removeChild
I used above