2017-11-20 3 views
0

자바 스크립트 window.close() 함수

function validateLoginForm(){ 
 
\t \t var str = ''; 
 
\t \t if(trim(document.getElementById('userName').value)=='') 
 
\t \t \t str = 'UserName is Required\r\n'; 
 
\t \t if(trim(document.getElementById('password').value)=='') 
 
\t \t \t str = str+'Password is Required'; 
 
\t \t if(str=='') 
 
\t \t \t return true; 
 
\t \t else{ 
 
\t \t \t alert(str); 
 
\t \t \t return false; \t 
 
\t \t } 
 
\t } 
 
    
 
function myOpenWindow() { 
 
\t \t var rand_no = Math.round(1000*Math.random()); 
 
\t \t 
 
\t \t if(window.name == "IMSWindowName"){ 
 
\t \t  windowName = "IMSWindowNameFirst"+rand_no; 
 
\t \t  windowName = "_self"+rand_no; 
 
\t \t }else{ 
 
\t \t  windowName = "IMSWindowName"+rand_no; 
 
\t \t  windowName = "_self"+rand_no; 
 
\t \t } 
 
\t \t heightVal=screen.height-150; 
 
\t \t widthVal=screen.width-150; 
 
\t \t 
 
\t \t newwin2 = window.open('',windowName,'toolbar=no,status=0,resizable=1,scrollbars=1,top=0,left=0,height='+heightVal+',width='+widthVal+''); 
 
\t \t document.forms[0].target=windowName; 
 
\t \t document.forms[0].action='LogIn'; 
 
\t \t document.forms[0].method='post'; 
 
\t \t newwin2.focus(); 
 
\t \t window.opener='X'; 
 
\t \t window.open('','_parent',''); 
 
\t \t window.close(); 
 
\t }
<input type=submit class="myButton" value="Sign In" title="Ok" onClick="if(validateLoginForm()){myOpenWindow();quitBox('quit');}else{return false;}"/></td><td><input type=button class="myButton" value="Clear" title="Reset" onClick="document.forms[0].reset();"/>

내가가 로그인 할 때 자동으로 로그인 창을 닫습니다.이 코드는 IE 브라우저에서 완벽하게 작동이 코드를 시도했지만 같은 다른 브라우저에서 작동하는 데 실패 크롬과 파이어 폭스? 당신은이 구문을 사용할 수 있습니다

+0

이 링크 및 모질라 –

답변

0

,

if(document.getElementById('userName').value.trim()=='') 

확인이 자동으로 크롬에서 로그인 페이지를 닫 코드에 대해 묻는 나의 질문 .I에 대한 답변을하지 않습니다 더에 String.prototype.trim()