2017-09-29 4 views
0

나는 안드로이드 인터넷 브라우저를 대상으로하는 테스트 프로젝트를 진행 중이다. javascript를 사용하여 일부 객체 onLoad를 숨기고 있습니다.안드로이드 인터넷 브라우저에서 HTML의 요소를 숨기기

문제는 Mozilla Firefox에서 작동하지만 Android 기본 인터넷 브라우저에서 작동하지 않는다는 것입니다.

<!DOCTYPE html> 
<html> 

<script type="text/javascript" async> 

function ajaxpath_59c479660b217(url){return window.location.href == '' ? url : url.replace('&s=','&s=' + escape(window.location.href));}(function(){document.write('<div id="fcs_div_59c479660b217"></div>');fcs_59c479660b217=document.createElement('script');fcs_59c479660b217.type="text/javascript";fcs_59c479660b217.src=ajaxpath_59c479660b217((document.location.protocol=="https:"?"https:":"http:")+"//www.freecommentscript.com/GetComments2.php?p=59c479660b217&s=#!59c479660b217");setTimeout("document.getElementById('fcs_div_59c479660b217').appendChild(fcs_59c479660b217)",1);})(); 

    function myFunction() { 
    document.getElementById("comment-ad").style.display = "none"; 
} 

function myFunction2() // no ';' here 
{ 
    var elem = document.getElementById("fcs_Comment_59c479660b217"); 
    if (elem.value=="Enter your comment here") elem.value = "Enter your post here"; 
    else elem.value = "Enter your post here"; 
} 

function myFunction3() // no ';' here 
{ 
     document.getElementById("comment-rss-feed").style.display = "none"; 

} 

function showFilterItem() { 
    if (filterstatus == 0) { 
     filterstatus = 1; 
     $find('<%=FileAdminRadGrid.ClientID %>').get_masterTableView().showFilterItem(); 
     document.getElementByClassName("ShowButton").innerHTML = "Hide Filter"; 
    } 
    else { 
     filterstatus = 0; 
     $find('<%=FileAdminRadGrid.ClientID %>').get_masterTableView().hideFilterItem(); 
     document.getElementById("ShowButton").innerHTML = "Show filter"; 
    } 
} 


if (document.readyState === "complete") { 
    myFunction(); 
    myFunction2(); 
    myFunction3(); 
    showFilterItem(); 
} 
else { 
    window.onload = function() { 
     myFunction(); 
     myFunction2(); 
     myFunction3(); 
     showFilterItem(); 
    }; 
}; 

</script> 


</body> 
</html> 
+0

HTML 요소를 숨기거나 추가하기 전에 스크립트가 추가 되었습니까? –

+0

나는 아무것도 제공하지 않은 스크립트를 사용하고 있습니다. – Arman

답변

0

내가 JS는 DOM 요소를 찾을 수 있는지 확인하기 위해 domloaded 경우에 전체 스크립트를 넣을 수 있습니다 :

여기 내 전체 코드입니다. 이렇게 :

<script type="text/javascript" async> 
document.addEventListener('DOMContentLoaded', function(){ 
function ajaxpath_59c479660b217(url){return window.location.href == '' ? url : url.replace('&s=','&s=' + escape(window.location.href));}(function(){document.write('<div id="fcs_div_59c479660b217"></div>');fcs_59c479660b217=document.createElement('script');fcs_59c479660b217.type="text/javascript";fcs_59c479660b217.src=ajaxpath_59c479660b217((document.location.protocol=="https:"?"https:":"http:")+"//www.freecommentscript.com/GetComments2.php?p=59c479660b217&s=#!59c479660b217");setTimeout("document.getElementById('fcs_div_59c479660b217').appendChild(fcs_59c479660b217)",1);})(); 

    function myFunction() { 
    document.getElementById("comment-ad").style.display = "none"; 
} 

function myFunction2() // no ';' here 
{ 
    var elem = document.getElementById("fcs_Comment_59c479660b217"); 
    if (elem.value=="Enter your comment here") elem.value = "Enter your post here"; 
    else elem.value = "Enter your post here"; 
} 

function myFunction3() // no ';' here 
{ 
     document.getElementById("comment-rss-feed").style.display = "none"; 

} 

function showFilterItem() { 
    if (filterstatus == 0) { 
     filterstatus = 1; 
     $find('<%=FileAdminRadGrid.ClientID %>').get_masterTableView().showFilterItem(); 
     document.getElementByClassName("ShowButton").innerHTML = "Hide Filter"; 
    } 
    else { 
     filterstatus = 0; 
     $find('<%=FileAdminRadGrid.ClientID %>').get_masterTableView().hideFilterItem(); 
     document.getElementById("ShowButton").innerHTML = "Show filter"; 
    } 
} 


if (document.readyState === "complete") { 
    myFunction(); 
    myFunction2(); 
    myFunction3(); 
    showFilterItem(); 
} 
else { 
    window.onload = function() { 
     myFunction(); 
     myFunction2(); 
     myFunction3(); 
     showFilterItem(); 
    }; 
}; 
}); 
</script> 
+0

DOM을 처음 사용했습니다. 가능한 경우 당신이 제안하고있는 것을 보여줄 수 있습니까? – Arman

+0

스크립트에서 일부 DOM 요소 (예 : document.getElementByID ('xxx'))를 처리하려고 할 때 - 자바 스크립트는이 요소를 찾아 관련 코드를 실행해야합니다. Javascript가이 요소를 찾을 수없는 경우 문제가 발생합니다 (dom에서 렌더링이 준비되지 않았으므로). 이 문제를 해결하기 위해 모든 DOM 요소가로드되고 자바 스크립트에서 액세스 할 수 있는지 확인하기 위해 내 이벤트에서 이벤트 리스너를 사용할 수 있습니다. –