'location'에 해당되는 글 2건

  1. 2016.07.13 [HTML] window.history 스펙
  2. 2011.11.22 Javascript queryString 맛보기

[HTML] window.history 스펙

ITWeb/개발일반 2016. 7. 13. 17:50

window.history 스펙이라기 보다 그냥 history interface 내용을 가져온 것입니다.


원문)

https://html.spec.whatwg.org/multipage/browsers.html#the-history-interface


내용)

enum ScrollRestoration { "auto", "manual" };

interface History {
  readonly attribute unsigned long length;
  attribute ScrollRestoration scrollRestoration;
  readonly attribute any state;
  void go(optional long delta = 0);
  void back();
  void forward();
  void pushState(any data, DOMString title, optional USVString? url = null);
  void replaceState(any data, DOMString title, optional USVString? url = null);
};


본 내용을 찾아본 이유는 location.href 값을 변경하고 싶었고 변경 시 reloading 되지 않도록 하기 위해서 입니다.

pushState, replaceState 를 이용하면 원하는 기능을 구현 할 수 있습니다.


설명)

window . history . length

Returns the number of entries in the joint session history.

window . history . scrollRestoration [ = value ]

Returns the scroll restoration mode of the current entry in the session history.

Can be set, to change the scroll restoration mode of the current entry in the session history.

window . history . state

Returns the current state object.

window . history . go( [ delta ] )

Goes back or forward the specified number of steps in the joint session history.

A zero delta will reload the current page.

If the delta is out of range, does nothing.

window . history . back()

Goes back one step in the joint session history.

If there is no previous page, does nothing.

window . history . forward()

Goes forward one step in the joint session history.

If there is no next page, does nothing.

window . history . pushState(data, title [, url ] )

Pushes the given data onto the session history, with the given title, and, if provided and not null, the given URL.

window . history . replaceState(data, title [, url ] )

Updates the current entry in the session history to have the given data, title, and, if provided and not null, URL.


:

Javascript queryString 맛보기

ITWeb/개발일반 2011. 11. 22. 11:15
가끔 Server Side 말고 Client 만 가지고 queryString 처리를 해야 할 때가 있습니다.
그래서 그냥 하드코딩 올려 봅니다.

[참고URL]
http://www.w3schools.com/jsref/jsref_split.asp
http://www.w3schools.com/jsref/obj_location.asp
http://www.w3schools.com/jsref/prop_loc_href.asp

// 예) http://www.my.com/index.html?width=320&height=48&allow=my.com

<script type="text/javascript">

var href = window.location.href;

var queryString = href.split('?');

var params = queryString[1].split('&');

var size = params.length;


for ( var i=0; i<size; i++ ) {

var param = params[i].split('=');
        alert('KEY : ' + param[0] + "\n" + 'VALUE : ' + param[1]);

}

</script>



[추가정보]
- document.URL : 읽기 전용으로 동일한 정보를 가져 옵니다.
- document.location : 읽기/쓰기 가능 하며 동일한 정보를 가져 옵니다.
- location.search : ?width=320&height=48&allow=my.com 이 부분만 가져 옵니다.


 
: