[javascript] 새로고침 없이 파라미터 제거/수정
Remove URL parameters without refreshing page
window.history.pushState({}, document.title, "/" + myNewURL );
https://stackoverflow.com/questions/22753052/remove-url-parameters-without-refreshing-page
Remove URL parameters without refreshing page
I am trying to remove everything after the "?" in the browser url on document ready. Here is what I am trying: jQuery(document).ready(function($) { var url = window.location.href; url = url...
stackoverflow.com
1- The pushState() method if you want to add a new modified URL to history entries.
2- The replaceState() method if you want to update/replace current history entry.
.replaceState() operates exactly like .pushState() except that .replaceState()
For one liner fans, try this out in your console/firebug and this page URL will change:
window.history.pushState("object or string", "Title", "/"+window.location.href.substring(window.location.href.lastIndexOf('/') + 1).split("?")[0]);
This page URL will change from:
http://stackoverflow.com/questions/22753052/remove-url-parameters-without-refreshing-page/22753103#22753103
To
http://stackoverflow.com/22753103#22753103
History: pushState() method
https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
History: pushState() method - Web APIs | MDN
In an HTML document, the history.pushState() method adds an entry to the browser's session history stack.
developer.mozilla.org
History.replaceState() https://developer.mozilla.org/ko/docs/Web/API/History/replaceState
History.replaceState() - Web API | MDN
History.replaceState() 메서드는 현재 history를 수정해 메소드의 매개 변수에 전달 된 stateObj, title, URL로 대체합니다. 이 방법은 특히 일부 유저의 동작에 대한 응답으로 history 객체의 상태나 현재 history
developer.mozilla.org
'프로그래밍 > Script' 카테고리의 다른 글
스크립트 정규식을 화면으로 보여주는 사이트 - regulex (0) | 2023.08.22 |
---|---|
[javascript] history.pushState ( 화면 전환 ) (0) | 2023.08.08 |
[javascript] 파라미터 제거하기. remove url parameters with javascript or jquery (0) | 2023.08.03 |
[JAVASCRIPT] 25 Killer JavaScript One-Liners That’ll Make You Look Like a Pro (0) | 2023.08.03 |
[jQuery] 숫자에 콤마 제거, replace comma (0) | 2023.07.28 |