2014-03-24 87 views
1

我想將網頁顯示爲模式彈出窗口。ShowModalDialog面臨問題

Response.Write("<script type='text/javascript'>detailedresults=window.showModalDialog('NewFile.aspx','Data','left=(screen.width) ? (screen.width - 800)/2 : 0,top=(screen.height) ? (screen.height - 700)/2 : 0,width=1000, height=500, toolbar=no, menubar=no, titlebar=no, location=no, addressbar=no');</script>"); 

雖然使用上面的代碼。我能夠將網頁顯示爲模態彈出窗口,但問題是它還打開了第三個窗口,它是具有相同名稱的網頁,而不是模式彈出窗口。

請幫我解決這個問題。提前致謝。

回答

0

而不是寫劇本出來響應使用RegisterStartupScript代替:

Page.ClientScript.RegisterStartupScript(this.GetType(), 
       "detailedresults", 
       "<script type='text/javascript'>detailedresults=window.showModalDialog('NewFile.aspx','Data','left=(screen.width) ? (screen.width - 800)/2 : 0,top=(screen.height) ? (screen.height - 700)/2 : 0,width=1000, height=500, toolbar=no, menubar=no, titlebar=no, location=no, addressbar=no');</script>"); 
+0

謝謝..這爲我工作。隨着你的代碼,我不得不在'NewFile.aspx'中添加下面的代碼...''base target =「_ self」/>' – PamZy