새 창 띄우기
새 창을 띄우려면 window.open() 이라는 자바스크립트 기본 함수를 사용합니다. 문법은 window.open(url, wname, wopt)입니다.
- url: 문자열, 새 창이 표시할 내용인 웹 문서의 URL
- wname: 문자열, 새 창의 이름(타겟명). 특별히 필요없으면 공백문자열("")을 지정
- wopt: 문자열, 창의 속성을 지정 (예: "width=350,height=400,scrollbars=yes,menubar=no")
- 링크를 클릭할 때 새 창 띄우기
<a href="javascript:void(window.open('http://jsguide.net','JSGUIDE','width=320,height=240'))">Link</a>
또는
<a href="#" onClick="window.open('http://jsguide.net','JSGUIDE','width=320,height=240');return false">Link</a> - 버튼을 클릭할 때 새 창 띄우기
<input type="button" value="JSGUIDE" onClick="window.open('http://jsguide.net','JSGUIDE','width=320,height=240')">
- 현재 문서가 로딩완료될 때 새 창 띄우기
<BODY onLoad="window.open('http://jsguide.net','JSGUIDE','width=320,height=240')">
- 무조건 새 창 띄우기
<HEAD>
...
<script langauge="javascript">
window.open("http://jsguide.net","JSGUIDE","width=320,height=240");
</script> - 5초 후에 새 창 띄우기
<HEAD>
...
<script langauge="javascript">
setTimeout("window.open('http://jsguide.net','JSGUIDE','width=320,height=240')",5000);
</script> -
href 의 url 을 이용.
<script type="text/javascript">
function pop(a)
{
url = a.getAttribute("href");
window.open(url,'popup','width=200,height=400');
return false;
}
</script>
<a href="http://www.google.de" target="_blank" onclick="return pop(this);">open google</a>
'java script' 카테고리의 다른 글
새로운 창 열기 막는 법 (0) | 2011.01.07 |
---|---|
소스 보기 막는 법 (0) | 2011.01.07 |
브라우저 내장객체-location 객체 href, reload() (0) | 2011.01.07 |
엔터키 체크 (0) | 2011.01.07 |
맨위로 이동하는 방법 (0) | 2011.01.07 |