2014-09-16 1 views
0

:같이 IndexOf 문제 해결이 부분은 결과를 반환하는 방법을 제공

var s = "foo"; 
alert(s.indexOf("oo") > -1); 

을하지만이 부분은하지 않습니다

var currentLocation = window.location; 
alert(currentLocation.indexOf(".") > -1); 
+1

베카를 보려면 'window.location'을 사용하는 것은 문자열이나 배열이 아니므로 [Location 객체] (https://developer.mozilla.org/en-US/docs/Web/API/Location)입니다.'window.location .toString()' – mpcabd

+0

답변 해 주셔서 감사합니다. 그러나 정답을 표시하는 측면에서 이것이 어떻게 작동하는지 확신 할 수 없습니다. mpcabd가 시위를하지 않는다면 Scimonster –

+0

에 그걸 줄 거예요. 나는 그의 대답에 대해 투표 할 것입니다. – mpcabd

답변

2

window.locaton 때문에 문자열이 아닌. several properties 인 객체입니다.

전체 URL (점이 포함될 수 있음)은 window.location.href이거나 도메인 뒤의 경로는 window.location.pathname인지 확인할 수 있습니다.

+0

다른 사용자의 의견에서 솔루션을 가져 오는 것에 대한 비난을 사전에 방지하기 위해 의견을 게시하기 전에 썼습니다 만 인터넷 연결이 끊어지기 때문에 게시 할 수 없습니다. – Scimonster

+0

걱정 마세요 :) 우리는 모두 도와주고 있습니다. – mpcabd

+0

@mpcabd 감사합니다. 나는 실제로 다른 시간에 나는 downvotes와 표절 혐의를 실제로 받았기 때문에 그렇게했다. – Scimonster

0

window.location.toString()

var currentLocation = window.location.toString(); 
alert(currentLocation.indexOf(".")); 

DEMO 모든 속성

showLoc(); 
function showLoc() { 
    var oLocation = window.location, aLog = ["Property (Typeof): Value", "window.location (" + (typeof oLocation) + "): " + oLocation ]; 
    for (var sProp in oLocation){ 
    aLog.push(sProp + " (" + (typeof oLocation[sProp]) + "): " + (oLocation[sProp] || "n/a")); 
    } 
    alert(aLog.join("\n")); 
} 

DEMO