브라우저 객체_JavaScript

miin·2023년 12월 12일
0

Java Script

목록 보기
33/36
post-thumbnail

window

모든 객체가 소속된 객체이며, 브라우저 창을 의미한다
window는 생략이 가능하다

  • window.open(page url, target, option) //('www.naver.com','_blanck','width=300px,height=300px')
    더 많은 옵션들이 있음
  • window.opener: 팝업창에서 자신을 오픈한 부모창을 제어
    - 팝업창에서 부모창으로 값 넘기기 -> window.opener.폼이름.객체.value = document.폼이름.객체.value
    • 팝업창에서 부모창 함수 호출하기 -> window.opener.함수명()
    • 팝업창에서 부모창으로 메세지 보내기 -> window.opener.postMessage({key:'test'}, window.location.origin)
      부모창에서 받기
useEffect(() => {
const handleMessage = event => {
    if(event.origin === window.location.origin){
      if(evnet.data.key === 'test'){
        refetchData();
      }
    }
}
window.addEventListener('message', handleMessage);
return () => {
  window.removeEventListener('message', handleMessage);
}
},[reqbody])

참고 블로그

window.open('www.dddd.com')
window.close()
window.alert('')

open('www.dddd.com')
close()
alert('')

document

현재문서에 대한 정보를 갖고 있는 객체

document.qeurySelector('#ss').textContent='원하는 텍스트'

history

현재의 브라우저가 접근했던 URL history를 제어할 수 있다
브라우저의 뒤로가기 앞으로가기의 기능과 유사하다

history.back()
history.forward()

location

문서의 주소와 관련된 객체로 window객체의 프로퍼티인 동시에 document의 프로퍼티이다
이 객체를 이용하여 윈도우의 문서 URL을 변경할 수 있고,
문저의 위치와 관련해서 다양한 정보를 얻을 수 있다

window.location(o)
document.location(o)

location.host //홈페이지의 host
location.href='www.google.com'

실행중인 애플리케이션에 대한 정보를 알 수 있다
크로스 브라우징 이슈를 해결할때 사용할 수 있다
사용자의 위치를 가져올 때에도 유용하게 사용된다

  • navigator.geolocation.getCurrentPostition() 현재 애플리케이션에 대한 위치정보
  • navigator.appName 앱(브라우저) 이름을 반환
  • navigator.appVersion 앱(브라우저)에 대한 버전 정보를 반화
  • navigator.userAgent 서버에 요청할때 앱(브라우저)에 대한 정보

위치정보 레퍼런스

0개의 댓글

관련 채용 정보