window.open 開啟是空白頁面

來源:互聯網
上載者:User

眾所周知,FireFox為了支援web標準,在1.1版以後就取消了對強制回應對話方塊的支援。即:window.showModalDialog()。但是我們有時在製作網頁的時候想增強使用者體驗性,想使用這個功能怎麼辦?我們先來分析一下實現強制回應對話方塊的原理,我們在IE的強制回應對話方塊下無論點父視窗的什麼地方,focus(焦點)總是回到了子視窗上面。那麼在FireFox下我們將focus總是設定在子視窗上不就行了嘛。怎麼設定呢?javascript 有一個定時執行函數的操作似乎可以不斷地將子視窗設定為focus(我也沒有去測試是否可以,就不能說一定可以了),但是我們沒有必要這麼麻煩,因為只需當使用者點擊父視窗的時候設定一下就行了,很幸運,FireFox支援window.onclick事件。那麼我們一起來動手寫一個既支援IE又支援 FireFox的“強制回應對話方塊”函數:
<script type="text/javascript" >
function modalWin(url)
{
       if (window.showModalDialog)
       {
          window.showModalDialog(url,'write',"dialogWidth:500px;dialogHeight:300px");
       }
       else
       {  
          var       w=window.screen.width;  
          var       h= window.screen.height;  
          var       winwidth=500;  
          var       winheight=300;  
          var       win= (h - winheight)/2;  
          var       winleft= (w- winwidth)/2;  
          window.myAction=this;
          var DialogWin =       window.open(url, 'write',"top="+win+",left="+winleft+',width=500px,height=300px,modal=yes');
          window.onclick=function (){DialogWin.focus()};
       }
}
</script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.