JavaScript中的弹出窗口

时间:2013-02-19 10:20:36

标签: javascript popup window blogger tumblr

我在基于Blogger的website上使用自定义Tumblr分享按钮,我希望在弹出窗口中打开共享屏幕。现在它将在新标签页中打开。

有人可以告诉我该怎么做吗?

<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>

2 个答案:

答案 0 :(得分:1)

   <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>

检查http://jsfiddle.net/gzMXd/

上的演示代码

答案 1 :(得分:0)

使用javascript window.open()功能

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

语法:

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

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