简体   繁体   English

JavaScript中的弹出窗口

[英]Pop-up window in JavaScript

I'm using a custom Tumblr share button on my Blogger-based website and I'd like the share screen to open in a pop-up window. 我在基于Blogger的网站上使用了自定义的Tumblr共享按钮,并且希望在弹出窗口中打开共享屏幕。 Right now it opens in a new tab. 现在,它将在新选项卡中打开。

Can someone please show me how to do this? 有人可以告诉我该怎么做吗?

<div class='tumblr-button'>
<script>
var strPostUrl = "<data:post.url/>";
var strPostTitle = '<data:post.title/>';
var strNewUrl = strPostUrl.replace("http://","");
var strNewTitle = strPostTitle.replace(/"/g, '"');
document.write("<a href='http://www.tumblr.com/share/link?url="+strNewUrl+"&amp;name="+strNewTitle+"' target='_new'><img src='http://platform.tumblr.com/v1/share_1.png'/></a>");
</script>
</div>
   <div class='tumblr-button'>
    <script>
    var strPostUrl = "http://google.com";
    var strPostTitle = 'Google';
    var strNewUrl = strPostUrl.replace("http://","");
    var strNewTitle = strPostTitle.replace(/"/g, '"');

    </script>
    <a href='javascript:void(0);' id='tumblr'><img src='http://platform.tumblr.com/v1/share_1.png'/></a>
</div>
    <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#tumblr').click(function(){
         var width  = 775,
            height = 500,
            left   = ($(window).width()  - width)  / 2,
            top    = ($(window).height() - height) / 2,        
            opts   = 'status=1' +
            ',width='  + width  +
            ',height=' + height +
            ',top='    + top    +
             ',left='   + left;
    var url = "http://www.tumblr.com/share/link?url="+strNewUrl+"&name="+strNewTitle;
    window.open(url , 'tumblr', opts);
    });
   });
    </script>

check demo code on http://jsfiddle.net/gzMXd/ http://jsfiddle.net/gzMXd/上查看演示代码

Use javascript window.open() function 使用javascript window.open()函数

$('#buttonID').click(function() {
  myWindow=window.open('','','width=200,height=100');  
  myWindow.document.write("<p>This is 'myWindow'</p>");  
  myWindow.focus();  
});

Syntax: 句法:

window.open (URL, windowName[, windowFeatures])

eg. 例如。 window.open ("http://jsc.simfatic-solutions.com", "mywindow","status=1,toolbar=1");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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