Window Popup 2007-08-28 11:20:46
<strong>Một số cách để open 1 windows mới</strong><br />
<u>cách 1</u>: cách đơn giản nhất
Demo: <a href="http://phpbasic.com" target="_blank">PHPBASIC</a><br />
<u>Cách 2</u>:
<script>var new_window;
function popup(url)
{ new_window=window.open(url,'name','height=800,width=600');
if (window.focus) {new_window.focus()}
}</script>
Demo:
<a href="javascript:popup('http://phpbasic.com');">Click here</a><br />
* nội dung của cửa sổ là nội dung của url
<br />
Cách 3:
<script type="text/javascript">
function popup()
{
var generator=window.open('','name','height=300,width=400,status=1');
generator.document.write('<html><head><title>Popup</title>');
generator.document.write('</head><body>');
generator.document.write('<h1>Welcome to phpbasic.com</h1>');
generator.document.write('<p>Noi dung cua o cua so nay do javascript qui dinh.</p>');
generator.document.write('<p><a href="javascript:alert(self.location.href)">Xem URL cua window</a>.</p>');
generator.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
generator.document.write('</body></html>');
generator.document.close();
}
</script>
<a href="javascript:popup();">Click here</a>
<script type="text/javascript">
function popup2()
{
var generator=window.open('','name','height=300,width=400,status=1');
generator.document.write('<html><head><title>Popup</title>');
generator.document.write('</head><body>');
generator.document.write('<h1>Welcome to phpbasic.com</h1>');
generator.document.write('<p>Noi dung cua o cua so nay do javascript qui dinh.</p>');
generator.document.write('<p><a href="javascript:alert(self.location.href)">Xem URL cua window</a>.</p>');
generator.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
generator.document.write('</body></html>');
generator.document.close();
}
</script>
Demo:
<a href="javascript:popup2();">Click here</a><br />
* nội dung của cửa sổ do javascript qui định
<br />
<u>Ghi chú</u>:
Đối số thứ 3 của hàm window.open có thể bao gồm các thuộc tính sau:
- height: chiều cao của popup, chỉ dùng đơn vị pixel (không dùng %)
- width: chiều rộng của popup, chỉ dùng đơn vị pixel (không dùng %)
- left: vị trí của popup so với lề trái của cửa sổ lớn
- top:vị trí của popup so với lề trái của cửa sổ lớn
- resizable: resize được kích thước của popup nếu là true
- scrollbars: xuất hiện scrollbars(thanh trượt) nếu là true
- toolbar: xuất hiên toolbar nếu là true
- menubar: xuất hiện menubar(File, Edit, ...) nếu là true
- location: hiển thị thanh điạ chỉ
- status: hiển thị status cho popup
<br />
<u>focus và close cho popup</u>
<u>cách 1</u>: cách đơn giản nhất
<a href="http://phpbasic.com" target="_blank">PHPBASIC</a>
Demo: <a href="http://phpbasic.com" target="_blank">PHPBASIC</a><br />
<u>Cách 2</u>:
<script>var new_window;
function popup(url)
{ new_window=window.open(url,'name','height=800,width=600');
if (window.focus) {new_window.focus()}
}</script>
<a href="javascript:popup('http://phpbasic.com');">Click here</a>
function popup(url)
{ new_window=window.open(url,'name','height=800,width=600');
if (window.focus) {new_window.focus()}
}</script>
<a href="javascript:popup('http://phpbasic.com');">Click here</a>
<script>var new_window;
function popup(url)
{ new_window=window.open(url,'name','height=800,width=600');
if (window.focus) {new_window.focus()}
}</script>
Demo:
<a href="javascript:popup('http://phpbasic.com');">Click here</a><br />
* nội dung của cửa sổ là nội dung của url
<br />
Cách 3:
<script type="text/javascript">
function popup()
{
var generator=window.open('','name','height=300,width=400,status=1');
generator.document.write('<html><head><title>Popup</title>');
generator.document.write('</head><body>');
generator.document.write('<h1>Welcome to phpbasic.com</h1>');
generator.document.write('<p>Noi dung cua o cua so nay do javascript qui dinh.</p>');
generator.document.write('<p><a href="javascript:alert(self.location.href)">Xem URL cua window</a>.</p>');
generator.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
generator.document.write('</body></html>');
generator.document.close();
}
</script>
<a href="javascript:popup();">Click here</a>
<script type="text/javascript">
function popup2()
{
var generator=window.open('','name','height=300,width=400,status=1');
generator.document.write('<html><head><title>Popup</title>');
generator.document.write('</head><body>');
generator.document.write('<h1>Welcome to phpbasic.com</h1>');
generator.document.write('<p>Noi dung cua o cua so nay do javascript qui dinh.</p>');
generator.document.write('<p><a href="javascript:alert(self.location.href)">Xem URL cua window</a>.</p>');
generator.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
generator.document.write('</body></html>');
generator.document.close();
}
</script>
Demo:
<a href="javascript:popup2();">Click here</a><br />
* nội dung của cửa sổ do javascript qui định
<br />
<u>Ghi chú</u>:
Đối số thứ 3 của hàm window.open có thể bao gồm các thuộc tính sau:
- height: chiều cao của popup, chỉ dùng đơn vị pixel (không dùng %)
- width: chiều rộng của popup, chỉ dùng đơn vị pixel (không dùng %)
- left: vị trí của popup so với lề trái của cửa sổ lớn
- top:vị trí của popup so với lề trái của cửa sổ lớn
- resizable: resize được kích thước của popup nếu là true
- scrollbars: xuất hiện scrollbars(thanh trượt) nếu là true
- toolbar: xuất hiên toolbar nếu là true
- menubar: xuất hiện menubar(File, Edit, ...) nếu là true
- location: hiển thị thanh điạ chỉ
- status: hiển thị status cho popup
<br />
<u>focus và close cho popup</u>
if (window.focus) {new_window.focus()} // focus
<a href="javascript:if(new_window) new_window.close()">Close</a>
<a href="javascript:if(new_window) new_window.close()">Close</a>
Tra loi 12 comment(s) 2007-08-28 11:20:46
HQ 2007-08-30 05:06:48
Tra loi
TG 2007-08-30 05:12:59
................
</form>
Tra loi
HQ 2007-08-31 09:05:20
<form action="submit.php" method="post" name="form1" target="_blank" id="form1">
<input type="text" name="text1">
<input type="submit" value="Submit" name="B1">
</form>
File submit.php sẽ lấy giá trị của Text1 để xử lý
Bây giờ em muốn trang submit.php sẽ được mở trong cửa sổ popup theo cách 2 của bác.
Nhưng em ko biết truyền như thế nào.
Em làm theo cách của bác là khai action = "", rồi gọi popup(root_dir/submit.php) khi click nút Submit.
Nhưng nếu gọi như vậy thì nó không lấy được giá trị của Text1.
????
Tra loi
TG 2007-08-31 09:48:08
Tra loi
HQ 2007-08-31 09:58:24
Tra loi
HQ 2007-09-18 05:03:14
Tra loi
TG 2007-09-19 12:51:26
Tra loi
uoon 2007-09-29 03:27:05
Mình chưa thử bao giờ, bởi từ đầu toàn submit nhờ ajax.
<body>
<form name="uoon" action="#" onsubmit="alert(document.uoon.test.value); return false;">
<input type="text" name="test" />
<input type="submit" value="test submit with js">
</form>
</html>
Tra loi
Vy Quang Hoà 2007-11-26 04:24:39
Tra loi
Quan Tran Anh 2007-11-26 05:58:47
Tra loi
CRA 2007-11-27 11:55:45
Thanks truoc nha
Tra loi
dotung23 2008-10-15 01:52:30
Tra loi
Y kien