當前位置:編程學習大全網 - 源碼下載 - 如何彈出固定大小和內容的網頁窗口

如何彈出固定大小和內容的網頁窗口

彈出匯總收集(續)

Asp教程-ASP應用程序

這個。response . Write(" & lt;腳本& gtwindow.open('WebForm7.aspx ','',' toolbar=no,location=no,directories = no,status=no,menubar=no,scrollbars=no,resizable=yes,width=750,height=470,left=80,top = 40 ');& lt/script >);

彈出與妳當前窗口是否有菜單工具欄無關。妳只需要在頁面中寫壹個腳本,它就會彈出來。舉個例子,

& lta href = # onclick = " window . open(' XXX . aspx ','窗口名稱','參數');"& gtxxxxx & lt/a & gt;

以下是彈出窗口的壹些參數,可以自己設置。參數用逗號分隔。

可選。string-列出用逗號分隔的對象表。每壹項都有自己的值,它們會被分開(比如“全屏=是,工具欄=是”)。支持以下功能。

Channelmode = {yes | no | 1 | 0}窗口中是否顯示梯形模式。默認為否。

directory = { yes | no | 1 | 0 }是否在窗口中顯示各種按鈕。默認值為是。

Fullscreen = {yes | no | 1 | 0}是否以全屏模式顯示瀏覽器。默認值為“否”。請小心使用該功能。因為此屬性可能會隱藏瀏覽器的標題欄和菜單,所以您必須提供壹個按鈕或其他提示來幫助用戶關閉此瀏覽窗口。ALT+F4可以關閉窗口。全屏窗口必須使用channelmode。

Height = number以像素為單位指定窗口的高度。最小值是100。

Left = number指定窗口到左邊界的距離,以像素為單位。值必須大於或等於0。

Location = {yes | no | 1 | 0}指定是否在窗口中顯示地址欄。默認值為是。

Menubar = {yes | no | 1 | 0}指定是否在窗口中顯示菜單欄。默認值為是。

Resizable = {yes | no | 1 | 0}指定是否在窗口中顯示可由用戶調整大小的句柄。默認值為是。

Scrollbars = {yes | no | 1 | 0}指定在窗口中顯示水平滾動條還是垂直滾動條。默認值為是。

Status = {yes | no | 1 | 0}指定狀態欄是否顯示在窗口中。默認值為是。

Titlebar = {yes | no | 1 | 0}指定標題欄是否顯示在窗口中。此項將被忽略,不調用HTML應用程序或對話框。默認值為是。

Toolbar = {yes | no | 1 | 0}指定是否在窗口中顯示工具欄,包括前進、後退和停止等按鈕。默認值為是。

Top = number以像素為單位指定窗口頂部的位置。值必須大於或等於0。

Width = number以像素為單位指定窗口的寬度。最小值是100。

1,最基本的彈出窗口代碼

& lt腳本語言= " javascript " & gt

& lt!-

window.open ('page.html ')

-& gt;

& lt/SCRIPT & gt;

因為這是壹段javascripts代碼,所以它們應該放在

2、設置後彈出窗口

先說壹下彈窗的設置。只需在上面的代碼中添加壹些內容。讓我們自定義這個彈出窗口的外觀、大小和彈出位置,以適合這個頁面的具體情況。

& lt腳本語言= " javascript " & gt

& lt!-

Window.open ('page.html ',' new window ',' height = 100,width = 400,top = 0,left = 0,toolbar = no,menubar = no,scrollbars = no,resizable = no,location = no,status。

-& gt;

& lt/SCRIPT & gt;

參數解釋:

& lt腳本語言= " javascript " & gtJs腳本啟動;

Window.open命令彈出壹個新窗口;

“page.html”彈出窗口的文件名;

“newwindow”彈出窗口的名稱(不是文件名)不是必需的,可以替換為空白“”;

高度=100窗戶高度;

寬度=400窗寬;

Top=從窗口到屏幕上方0像素值;

Left=距離屏幕左側的窗口的0像素值;

Toolbar =否是否顯示工具欄,是顯示;

菜單欄,滾動條代表菜單欄和滾動條。

Resizable=no是否允許改變窗口大小,yes是允許;

Location=no是否顯示地址欄,yes表示允許;

Status=no是否顯示狀態欄中的信息(通常文件已經打開),允許選擇yes

& lt/SCRIPT & gt;js腳本結束

3.用函數控制彈出窗口。

以下是完整的代碼。

& lthtml & gt

& lthead & gt

& lt腳本語言= " JavaScript " & gt

& lt!-

函數openwin() {

Window.open ("page.html "," new window "," height = 100,width = 400,toolbar = no,menubar = no,scrollbars = no,resizable = no,location = no,status = no ")//寫壹行。

}

//-& gt;

& lt/script & gt;

& lt/head & gt;

& ltbody onload = " open win()" & gt;

任何頁面內容...

& lt/body & gt;

& lt/html & gt;

這裏定義了壹個函數openwin(),函數的內容是打開壹個窗口。不調用是沒有用的。怎麽稱呼?

方法1:

方法二:

方法3:用連接呼叫:

& lta href = " # " onclick = " open win()" & gt;打開窗戶

註意:使用的“#”是虛擬連接。

方法4:用按鈕呼叫:

& ltinput type = " button " onclick = " open win()" value = " open window " >

4.兩個窗口同時彈出

對源代碼稍作修改:

& lt腳本語言= " JavaScript " & gt

& lt!-

函數openwin() {

Window.open ("page.html ","新窗口"," height = 100,width = 100,top = 0,left = 0,toolbar = no,scrollbars = no,resizable = no,location。

Window.open ("page2.html "," newwindow2 "," height = 100,width = 100,top = 100,left = 100,toolbar = No,menubar = No,scroll。

}

//-& gt;

& lt/script & gt;

為了避免兩個彈出窗口重疊,請使用top和left來控制彈出位置,以免彼此重疊。最後用上面說的四種方法調用。

註意:兩個窗口(newwindow和newwindow2)的名稱不應該相同,或者都應該為空。

5.在主窗口中打開文件1.htm,同時會彈出壹個小窗口page.html。

以下代碼被添加到主窗口中

& lt腳本語言= " javascript " & gt

& lt!-

函數openwin() {

window.open("page.html "," width=200,height=200 ")

}

//-& gt;

& lt/script & gt;

加入

& lta href = " 1 . htm " onclick = " open win()" & gt;打開& lt/a & gt;去做吧。

6.彈出窗口的定時關閉控制

再來控制壹下彈出窗口,效果會更好。如果我們在彈出頁面中添加壹小段代碼(註意是添加到page.html的html,而不是主頁面),讓它在10秒後自動關閉不是更酷嗎?

首先,將下面的代碼添加到< head & gt區域:

& lt腳本語言= " JavaScript " & gt

函數closeit()

{

Settimeout ("self.close()",10000)//ms。

}

& lt/script & gt;

然後呢。哎?lt;body onload = " close it()" & gt;這句話取代了page.html的原文

7.在彈出窗口中添加關閉按鈕。

& lt表單& gt

& ltINPUT TYPE = ' BUTTON ' VALUE = ' close ' onClick = ' window . close()' & gt;

& lt/FORM & gt;

呵呵,現在更完美了!

8.包含彈出窗口-壹頁上有兩個窗口

上面的例子都包含兩個窗口,壹個是主窗口,壹個是小彈出窗口。通過下面的例子,妳可以在壹個頁面中完成上面的效果。

& lthtml & gt

& lthead & gt

& lt腳本語言= " JavaScript " & gt

函數openwin()

{

OpenWindow=window.open("," newwin "," height=250,width=250,toolbar=no,scrollbars="+scroll+",menubar = no ");

//寫壹行

open window . document . write(" & lt;TITLE & gt例子

open window . document . write(" & lt;BODY BGCOLOR = # ffffff & gt)

open window . document . write(" & lt;h 1 & gt;妳好!& lt/h1 >)

OpenWindow.document.write("新窗口打開了!")

open window . document . write(" & lt;/BODY >)

open window . document . write(" & lt;/HTML >)

OpenWindow.document.close()

}

& lt/SCRIPT & gt;

& lt/head & gt;

& ltbody & gt

& lta href = " # " onclick = " open win()" & gt;打開窗戶

& ltinput type = " button " onclick = " open win()" value = " open window " >

& lt/body & gt;

& lt/html & gt;

查看OpenWindow.document.write()中的代碼。不是標準的HTML嗎?按照格式多寫幾行就行了。註意多壹個標簽或者少壹個標簽都會導致錯誤。記得以OpenWindow.document.close()結尾。

9、終極應用——彈出窗口的Cookie控件

回想起來,上面的彈出窗口很酷,但是有點問題。比如妳把上面的腳本放在壹個需要頻繁通過的頁面(比如首頁),這個頁面每刷新壹次窗口就會彈出壹次,那麽我們只要用cookie來控制就可以了。

首先,將以下代碼添加到

& lt腳本& gt

函數openwin(){

window.open("page.html "," width=200,height=200 ")

}

函數get_cookie(Name) {

var search = Name + "= "

var returnvalue =

if(document . cookie . length & gt;0) {

offset = document . cookie . index of(search)

如果(offset!= -1) {

偏移量+=搜索長度

end = document . cookie . index of(";",偏移);

if (end == -1)

end = document . cookie . length;

return value = unescape(document . cookie . substring(offset,end))

}

}

返回returnvalue

}

函數loadpopup(){

if (get_cookie('popped')==''){

openwin()

document.cookie="popped=yes "

}

}

& lt/script & gt;

然後,使用

  • 上一篇:如何寫出好的 PHP 代碼?
  • 下一篇:如何更新無線模塊WizFi210固件以支持SPI通信
  • copyright 2024編程學習大全網