- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company

Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Redirecting to a relative URL in JavaScript
My problem is that I want to redirect via JavaScript to a directory above.
The URL looks like this:
example.com/path/folder/index.php?file=abc&test=123&lol=cool
The redirect affect just this:
example.com/path/&test=123&lol=cool
But want to have this:
example.com/path/
How can I do it?

8 Answers 8
You can do a relative redirect:

- 43 see why you should use window.location.replace stackoverflow.com/questions/503093/… – gideon Dec 14, 2010 at 5:32
- 74 When you want to simulate a link, you should use window.location.href . You should only use window.location.replace when you want to simulate an http redirect (thus not generating a history item). – Benji XVI Oct 13, 2011 at 14:50
- 29 By the way, document.location was intended as a read-only property. It is safer to use window.location . See this question . – Benji XVI Oct 13, 2011 at 14:53
- 9 I found using window.location.href = '../' redirected to the root of the site and not "one level up" as expected. When the current page is "www.example.com/customers/list" I needed to use './' . I guess this is because "list" is not considered as a directory level. – Marcus Cunningham Nov 8, 2016 at 10:24
- 7 @MarcusCunningham, in your example, the directory is /customers/ - so "one level up" is www.example.com/. Now if your example URL was www.example.com/customers/list/ - it would redirect you to www.example.com/customers/ – Ubeogesh Jun 4, 2018 at 11:54
If you use location.hostname you will get your domain.com part. Then location.pathname will give you /path/folder. I would split location.pathname by / and reassemble the URL. But unless you need the querystring, you can just redirect to .. to go a directory above.
- My browser barks when I go location.path and it seems only to recognize location.pathname . Hints? – Konrad Viltersten Jan 9, 2016 at 20:19
- location.path is incorrect, it should be location.hostname. I've added an edit to the post to fix this. – ygrichman Jan 6, 2017 at 7:07
https://developer.mozilla.org/en-US/docs/Web/API/Location/assign
- window.location.assign("../"); // one level up
- window.location.assign("/path"); // relative to domain

- 1 the "/path" doesnt work for assign. It would not include the domain but just try to open "/path" – Pumuckelo Aug 2, 2022 at 12:12
redirect to ../
- 1 If your app is hosted in a sub-uri and the app doesn't know the sub-uri path. If you are at your apps root and you do ../ the app won't know how to get back to its root. For example, the same app is hosted at example.com/myapp and other.example.com/app2 – ReggieB Jan 16, 2014 at 9:29
<a href="..">no JS needed</a>
.. means parent directory.
- 16 That requires a click or some other user-initiated navigation. – recursive Sep 28, 2012 at 22:44
I'm trying to redirect my current web site to other section on the same page, using JavaScript. This follow code work for me:
try following js code
location = '..'

This is an old question but just to provide more information, this is how urls work:

Not the answer you're looking for? Browse other questions tagged javascript url redirect or ask your own question .
- The Overflow Blog
- How to position yourself to land the job you want
- Building an API is half the battle: Q&A with Marco Palladino from Kong
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- The Stack Exchange reputation system: What's working? What's not?
- Launching the CI/CD and R Collectives and community editing features for...
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
Hot Network Questions
- Under what circumstance is it a crime if a car owner allows someone other than themself to drive their car?
- Firefox very distorted, unusable
- How close do gravitational 2-body hierarchy levels get?
- Can a 13-year-old in the UK accept freelance work?
- ArcMap Field Calculator Python Parser gives ERROR 999999
- In Acts 8:32–33 was the Ethiopian eunuch reading a Septuagint scroll or a Hebrew scroll?
- What is the concept of hole in semiconductor physics?
- Why are most US news programs silent about Iran-Saudi deal announced at Beijing on March 10th?
- Is it possible to change the TeX hyphenation rules for Ecclesiastical Latin?
- How does inertia affect an object suspended in a fluid?
- Why is the ongoing auction for Silicon Valley Bank started privately held (vs. publicly)?
- A melody is built from both notes and chords
- How to preserve the order of expressions in the asymptotic expansion?
- Do cell-phone base station antennas emit the same power as cell phones?
- Short fantasy about disappearing items - Asimov's early 1980s
- Displaying Hasse diagram (directed edges in graph pointing upwards)
- Would these solar systems be stable?
- How useful is a caliper for a home-based bike workshop?
- Having centered equations with non centered text on the same line
- Finding a career as a researcher without any PhD, work experience, and/or relevant academic degree
- Implementation of a shared pointer constructors and destructor
- Where is the extra hour? Eurostar London to Paris is 2hr 30m but departure is 3hrs 30m before arrival
- Most polyominoes in an 8x8 grid
- How do you use unreliable narration when using an omnipotent narrator?
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .
- Data Structure & Algorithm Classes (Live)
- System Design (Live)
- DevOps(Live)
- Explore More Live Courses
- Interview Preparation Course
- Data Science (Live)
- GATE CS & IT 2024
- Data Structure & Algorithm-Self Paced(C++/JAVA)
- Data Structures & Algorithms in Python
- Explore More Self-Paced Courses
- C++ Programming - Beginner to Advanced
- Java Programming - Beginner to Advanced
- C Programming - Beginner to Advanced
- Full Stack Development with React & Node JS(Live)
- Java Backend Development(Live)
- Android App Development with Kotlin(Live)
- Python Backend Development with Django(Live)
- Complete Data Science Program(Live)
- Mastering Data Analytics
- DevOps Engineering - Planning to Production
- CBSE Class 12 Computer Science
- School Guide
- All Courses
- Linked List
- Binary Tree
- Binary Search Tree
- Advanced Data Structure
- All Data Structures
- Asymptotic Analysis
- Worst, Average and Best Cases
- Asymptotic Notations
- Little o and little omega notations
- Lower and Upper Bound Theory
- Analysis of Loops
- Solving Recurrences
- Amortized Analysis
- What does 'Space Complexity' mean ?
- Pseudo-polynomial Algorithms
- Polynomial Time Approximation Scheme
- A Time Complexity Question
- Searching Algorithms
- Sorting Algorithms
- Graph Algorithms
- Pattern Searching
- Geometric Algorithms
- Mathematical
- Bitwise Algorithms
- Randomized Algorithms
- Greedy Algorithms
- Dynamic Programming
- Divide and Conquer
- Backtracking
- Branch and Bound
- All Algorithms
- Company Preparation
- Practice Company Questions
- Interview Experiences
- Experienced Interviews
- Internship Interviews
- Competitive Programming
- Design Patterns
- System Design Tutorial
- Multiple Choice Quizzes
- Go Language
- Tailwind CSS
- Foundation CSS
- Materialize CSS
- Semantic UI
- Angular PrimeNG
- Angular ngx Bootstrap
- jQuery Mobile
- jQuery EasyUI
- React Bootstrap
- React Rebass
- React Desktop
- React Suite
- ReactJS Evergreen
- ReactJS Reactstrap
- BlueprintJS
- TensorFlow.js
- English Grammar
- School Programming
- Number System
- Trigonometry
- Probability
- Mensuration
- Class 8 Syllabus
- Class 9 Syllabus
- Class 10 Syllabus
- Class 11 Syllabus
- Class 8 Notes
- Class 9 Notes
- Class 10 Notes
- Class 11 Notes
- Class 12 Notes
- Class 8 Formulas
- Class 9 Formulas
- Class 10 Formulas
- Class 11 Formulas
- Class 8 Maths Solution
- Class 9 Maths Solution
- Class 10 Maths Solution
- Class 11 Maths Solution
- Class 12 Maths Solution
- Class 7 Notes
- History Class 7
- History Class 8
- History Class 9
- Geo. Class 7
- Geo. Class 8
- Geo. Class 9
- Civics Class 7
- Civics Class 8
- Business Studies (Class 11th)
- Microeconomics (Class 11th)
- Statistics for Economics (Class 11th)
- Business Studies (Class 12th)
- Accountancy (Class 12th)
- Macroeconomics (Class 12th)
- Machine Learning
- Data Science
- Mathematics
- Operating System
- Computer Networks
- Computer Organization and Architecture
- Theory of Computation
- Compiler Design
- Digital Logic
- Software Engineering
- GATE 2024 Live Course
- GATE Computer Science Notes
- Last Minute Notes
- GATE CS Solved Papers
- GATE CS Original Papers and Official Keys
- GATE CS 2023 Syllabus
- Important Topics for GATE CS
- GATE 2023 Important Dates
- Software Design Patterns
- HTML Cheat Sheet
- CSS Cheat Sheet
- Bootstrap Cheat Sheet
- JS Cheat Sheet
- jQuery Cheat Sheet
- Angular Cheat Sheet
- Facebook SDE Sheet
- Amazon SDE Sheet
- Apple SDE Sheet
- Netflix SDE Sheet
- Google SDE Sheet
- Wipro Coding Sheet
- Infosys Coding Sheet
- TCS Coding Sheet
- Cognizant Coding Sheet
- HCL Coding Sheet
- FAANG Coding Sheet
- Love Babbar Sheet
- Mass Recruiter Sheet
- Product-Based Coding Sheet
- Company-Wise Preparation Sheet
- Array Sheet
- String Sheet
- Graph Sheet
- ISRO CS Original Papers and Official Keys
- ISRO CS Solved Papers
- ISRO CS Syllabus for Scientist/Engineer Exam
- UGC NET CS Notes Paper II
- UGC NET CS Notes Paper III
- UGC NET CS Solved Papers
- Campus Ambassador Program
- School Ambassador Program
- Geek of the Month
- Campus Geek of the Month
- Placement Course
- Testimonials
- Student Chapter
- Geek on the Top
- Geography Notes
- History Notes
- Science & Tech. Notes
- Ethics Notes
- Polity Notes
- Economics Notes
- UPSC Previous Year Papers
- SSC CGL Syllabus
- General Studies
- Subjectwise Practice Papers
- Previous Year Papers
- SBI Clerk Syllabus
- General Awareness
- Quantitative Aptitude
- Reasoning Ability
- SBI Clerk Practice Papers
- SBI PO Syllabus
- SBI PO Practice Papers
- IBPS PO 2022 Syllabus
- English Notes
- Reasoning Notes
- Mock Question Papers
- IBPS Clerk Syllabus
- Apply for a Job
- Apply through Jobathon
- Hire through Jobathon
- All DSA Problems
- Problem of the Day
- GFG SDE Sheet
- Top 50 Array Problems
- Top 50 String Problems
- Top 50 Tree Problems
- Top 50 Graph Problems
- Top 50 DP Problems
- Solving For India-Hackthon
- GFG Weekly Coding Contest
- Job-A-Thon: Hiring Challenge
- BiWizard School Contest
- All Contests and Events
- Saved Videos
- What's New ?
- JS-Function
- JS-Generator
- JS-Expressions
- JS-ArrayBuffer
- JS-Tutorial
- Web Development
- Web-Technology
Related Articles
- Write Articles
- Pick Topics to write
- Guidelines to Write
- Get Technical Writing Internship
- Write an Interview Experience
How to redirect to a relative URL in JavaScript?
- JavaScript | Redirect a URL
- How to redirect to another webpage using JavaScript ?
- How to redirect a page to another page in HTML ?
- How to redirect to another webpage in HTML?
- Difference between ASP and ASP.NET
- Difference Between HTML and ASP
- Most commonly used tags in HTML
- HTML Introduction
- HTML Editors
- HTML Basics
- HTML | Layout
- HTML applet Tag
- HTML Tags – A to Z List
- HTML Elements
- HTML Attributes
- HTML Paragraphs
- HTML Text Formatting
- Tracxn Interview Experience | Set 2
- Tracxn Interview Experience
- Tracxn Interview Experience for SDE-2
- Tracxn Experienced Interview (3yrs SSE post)
- How to center a popup window on screen?
- How to Align modal content box to center of any screen?
- CSS | vertical-align Property
- How to calculate the number of days between two dates in JavaScript ?
- File uploading in React.js
- Hide elements in HTML using display property
- How to append HTML code to a div using JavaScript ?
- Difference between var and let in JavaScript
- Difficulty Level : Expert
- Last Updated : 31 Oct, 2019
This works in the same way as redirecting to any URL in javascript.
window.location.href returns the href (URL) of the current page
Example 1: A simple redirecting program
Both windows.location.href and document.location.href are same.
Example 2: A simple redirecting program
Please Login to comment...
- JavaScript-Misc
- Technical Scripter
New Course Launch!
Improve your Coding Skills with Practice
Start your coding journey now.
# window.location Cheatsheet
Looking for a site's URL information, then the window.location object is for you! Use its properties to get information on the current page address or use its methods to do some page redirect or refresh 💫
https://www.samanthaming.com/tidbits/?filter=JS#2
- Difference between host vs hostname
- How to change URL properties
- window.location vs location
- window.location.toString
- assign vs replace
- replace vs assign vs href
- Scratch your own itch 👍
- Community Input
# window.location Properties
# difference between host vs hostname.
In my above example, you will notice that host and hostname returns the value. So why do these properties. Well, it has do with the port number. Let's take a look.
URL without Port
https://www.samanthaming.com
URL with Port
https://www.samanthaming.com:8080
So host will include the port number, whereas hostname will only return the host name.
# How to change URL properties
Not only can you call these location properties to retrieve the URL information. You can use it to set new properties and change the URL. Let's see what I mean.
Here's the complete list of properties that you can change:
The only property you can't set is window.location.origin . This property is read-only.
# Location Object
The window.location returns a Location object. Which gives you information about the current location of the page. But you can also access the Location object in several ways.
The reason we can do this is because these are global variables in our browser.

# window.location vs location
All 4 of these properties point at the same Location object. I personally prefer window.location and would actually avoid using location . Mainly because location reads more like a generic term and someone might accidentally name their variable that, which would override the global variable. Take for example:
I think that most developer is aware that window is a global variable. So you're less likely to cause confusion. To be honest, I had no idea location was a global variable until I wrote this post 😅. So my recommendation is to be more explicit and use window.location instead 👍
Here's my personal order of preference:
Of course, this is just my preference. You're the expert of your codebase, there is no best way, the best way is always the one that works best for you and your team 🤓
# window.location Methods
# window.location.tostring.
This method returns the USVString of the URL. It is a read-only version of Location.href
In other words, you can use it to get the href value from the
on this 😊. But I did find a performance test on the difference.
JSPerf: Location toString vs Location href
One thing I want to note about these speed tests is that it is browser specific. Different browser and versions will render different outcome. I'm using Chrome, so the href came out faster then the rest. So that's one I'll use. Also I think it reads more explicit then toString() . It is very obvious that href will provide the URL whereas toString seems like something it being converted to a string 😅
# assign vs replace
Both of these methods will help you redirect or navigate to another URL. The difference is assign will save your current page in history, so your user can use the "back" button to navigate to it. Whereas with replace method, it doesn't save it. Confused? No problem, I was too. Let's walk through an example.
Current Page
I just need to emphasize the "current page" in the definition. It is the page right before you call assign or replace .
# How to Do a Page Redirect
By now, you know we can change the properties of the window.location by assigning a value using = . Similarly, there are methods we can access to do some actions. So in regards to "how to redirect to another page", well there are 3 ways.
# replace vs assign vs href
All three does redirect, the difference has to do with browser history. href and assign are the same here. It will save your current page in history, whereas replace won't. So if you prefer creating an experience where the navigation can't press back to the originating page, then use replace 👍
So the question now is href vs assign . I guess this will come to personal preference. I like the assign better because it's a method so it feels like I'm performing some action. Also there's an added bonus of it being easier to test. I've been writing a lot of Jest tests, so by using a method, it makes it way easier to mock.
But for that that are rooting for href to do a page redirect. I found a performance test and running in my version of Chrome, it was faster. Again performance test ranges with browser and different versions, it may be faster now, but perhaps in future browsers, the places might be swapped.
JSPerf: href vs assign
# Scratch your own itch 👍
Okay, a bit of a tangent and give you a glimpse of how this cheatsheet came to be. I was googling how to redirect to another page and encountered the window.location object. Sometimes I feel a developer is a journalist or detective - there's a lot of digging and combing through multiple sources for you to gather all the information available. Honestly, I was overwhelmed with the materials out there, they all covered different pieces, but I just wanted a single source. I couldn't find much, so I thought, I'll cover this in a tidbit cheatsheet! Scratch your own itch I always say 👍
# Community Input
: This is awesome, I’ve used window.location.href in the past, but didn’t realise how simple it is to access sections of the URL!
If you want to see a live-action of what James is talking about, check out the table of content at the top of this article. Click on it and it will scroll down to the specific section of the page.
# Resources
- Share to Twitter Twitter
- Share to Facebook Facebook
- Share to LinkedIn LinkedIn
- Share to Reddit Reddit
- Share to Hacker News Hacker News
- Email Email
Related Tidbits
Console.table to display data, colorful console message, window.location cheatsheet, fresh tidbits.

HTML abbr Tag

How to Pad a String with padStart and padEnd in JavaScript

Avoid Empty Class in Vue with Null

Fix Text Overlap with CSS white-space

How to Check if Object is Empty in JavaScript
How TO - Redirect to Another Webpage
Learn how to redirect to another webpage using JavaScript.

Redirect a Webpage
There are a couple of ways to redirect to another webpage with JavaScript. The most popular ones are location.href and location.replace :
Note: The difference between href and replace, is that replace() removes the URL of the current document from the document history, meaning that it is not possible to use the "back" button to navigate back to the original document.
Tip: For more information about the Location Object, read our Location Object Reference .

COLOR PICKER

Get your certification today!

Get certified by completing a course today!

Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
[email protected]
Your Suggestion:
Thank you for helping us.
Your message has been sent to W3Schools.
Top Tutorials
Top references, top examples, web certificates, get certified.

May 13, 2019
Member-only
How do you redirect to another page in Javascript?
There are many ways to redirect to another page. But which is the best?
More from All About Code
About Help Terms Privacy
Get the Medium app

All About Code
Text to speech

How to Redirect to a Relative URL in JavaScript?
Redirecting to a normal URL means sending the user to a URL no matter what that URL is or where it is placed. Directing to a relative URL means redirecting the user to a webpage placed in the same directory as the parent page or home page. Relative URLs can also be used to redirect to files placed in other directories, but the Relative URL would contain only the path and no other information like the domain.
This article will explain two different methods to redirect users to relative URLs but before that, quickly set up two different web pages by using the steps below:
Setting up the two HTML Documents
Create a new HTML document named home and put the following lines inside it:
This will display the following webpage on the browser:

After that, create another HTML document in the same directory (this is important to make it a relative URL) and name it as secondPage.html . After that, type the following lines in the secondPage.html:
Running the secondPage.html in the web browser gives the following outcome:

Setting up the web pages is done. Let’s move to the two different methods for relative URL redirecting.
Method 1: Using the Window Object to Redirect to a Relative URL
In the script file attached to the home.html webpage, create the following function:
Inside this function, use the window object to access its location property, and from that access the href and equal to the path of the secondPage.html. Since it is a relative URL (both the web pages are in the same directory), simply set the href to the name of the second webpage, which is secondPage.html . The function will look like this:
Run the home.html on a web browser and then observe the following functionality:
From the output, it is clear that pressing the button redirects the user to the secondPage.html using its relative URL
Method 2: Using the Document Object to Redirect to a Relative URL
Start by again creating the function created in method 1 with the following lines:
In this function, instead of the window object, this time around using the document object to access the location object. And then, from the location object, access the href property and set it equal to the relative path of the secondPage.html. Since the secondPage is in the same directory, the relative path would only be the name of the second webpage, which is the “secondPage.html”
It is clear that the user was redirected to the second by using the Relative of the second page with the help of JavaScript.
About the author

Abdul Mannan
I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.
- Nanodegree Programs
- Machine Learning Engineer for Microsoft Azure
- AI for Healthcare
- Intel® Edge AI for IoT Developers
- Machine Learning Engineer
- AI Product Manager
- AI Programming with Python
- Deep Learning
- Intro to Machine Learning with PyTorch
- Intro to Machine Learning with TensorFlow
- Data Structures and Algorithms
- Artificial Intelligence for Trading
- Computer Vision
- Natural Language Processing
- Deep Reinforcement Learning
- Artificial Intelligence
- AI for Business Leaders
- Self Driving Car Engineer
- Intro to Self-Driving Cars
- Robotics Software Engineer
- Flying Car and Autonomous Flight Engineer
- Sensor Fusion Engineer
- Activation and Retention Strategy
- Agile Software Development
- Data Science for Business Leaders
- Monetization Strategy
- Growth Product Manager
- Data Product Manager
- Product Manager
- Predictive Analytics for Business
- Digital Marketing
- Marketing Analytics
- Business Analytics
- Data Visualization
- UX Designer
- Cloud Computing for Business Leaders
- Hybrid Cloud Engineer
- Cloud Developer using Microsoft Azure
- Cloud DevOps using Microsoft Azure
- AWS Cloud Architect
- Cloud Developer
- Cloud DevOps Engineer
- Introduction to Cybersecurity
- Security Engineer
- Security Analyst
- Ethical Hacker
- Data Architect
- Data Analyst
- Data Scientist
- Data Engineer
Programming for Data Science with Python
- Programming for Data Science with R
- Data Streaming
- Data Analysis and Visualization with Power BI
- Intermediate Python
- RPA Developer with UiPath
- Intermediate JavaScript
- Java Web Developer
- Introduction to Programming
- iOS Developer
- Front End Web Developer
- Full Stack Web Developer
- Blockchain Developer
- Android Kotlin Developer
- Android Basics
- Java Programming
- Full Stack JavaScript Developer
- Full Catalog
- Career Prep
- Student Success
- Become A Mentor
- Become An Instructor
- Our Approach
- Corporate Social Responsibility
- For Government
- Get Started
Deciding on a Page Address with Window.location
Javascript is well-known for its ability to modify content on a web page. Less well-known is its ability to move between web pages programmatically so users don’t have to manipulate the browser manually by clicking on links or browser control buttons.
The Javascript standard provides an object called Window.location to handle changing a web page’s address and many other actions. These actions do not directly affect the Document Object Model (DOM) of a particular web page, and may load a new document.
The “location” part of Window.location is its own object type. The Location object is not unique to the Window object that controls the web browser. A single web page can support multiple Location objects.
Window.location is unique because it doesn’t require knowledge of anything on a web page to work. Location objects contain over a dozen properties and methods, and all of these are available to the unique Window.location object.
This article will cover the most commonly used properties and methods of Window.location .
Window.location.href
The window.location.href property returns the URL (Universal Resource Locator) of the current page. Developers can change this property by assigning a new value to it, and the browser will navigate to that new address when the assignment happens.
This example prints out the initial page address, http://example.com , then navigates to the Udacity home page using window.location.href .
Window.location.hostname
The window.location.hostname property returns the domain of a URL. Do not attempt to change this property in code; it will not redirect a web page to another location.
Window.location.pathname
The window.location.pathname property returns the path to the given web page on its server. For a URL that contains a domain but no additional server path, like https://example.com , the property would return an empty string.
The following example returns the path to my author page on the Udacity blog.
Window.location.port
The window.location.port property returns the port through which a web page is served to a user. Web browsers don’t usually show the default port in the address bar for common web protocols, but window.location.port can access them. Sometimes, depending on a server configuration, window.location.port will return an empty string if the default port isn’t shown in the address bar.
The following examples use window.location.port to show the default server ports for http: , https: , and a custom site configuration.
Window.location.protocol
The window.location.protocol property returns the web protocol a web page uses to transfer its information. The most common are http: and https: . These two protocols are similar, but the latter creates a secure connection, while the former does not.
Window.location.assign()
The window.location.assign() method works much like the property window.location.href . It navigates the browser to a new web page. The method has an advantage over the property, though, because the property doesn’t check whether its new URL is valid before trying to navigate.
The window.location.assign() method throws a DOMError if its URL is invalid. This gives developers a chance to catch errors without resorting to complicated URL string matching . Although window.location.href is arguably in more common usage, window.location.assign() is a safer, more robust option.
Window.location is a basic Javascript object that developers commonly rely on to navigate a web browser, but it also has other capabilities that programmers may not immediately be aware of. Changing a page’s address can affect Javascript print and output strategies , as well as raise security concerns.
Enroll in our Intro to Programming Nanodegree Program today to learn more about Window.location and other programming concepts.
Start Learning

Popular Nanodegrees
Data scientist nanodegree, self-driving car engineer, data analyst nanodegree, android basics nanodegree, intro to programming nanodegree, ai for trading, predictive analytics for business nanodegree, ai for business leaders, data structures & algorithms, school of artificial intelligence, school of cyber security, school of data science, school of business, school of autonomous systems, school of executive leadership, school of programming and development, related articles.

Parsing JSON in JavaScript.

About JavaScript’s “this” keyword.

Closures in JavaScript.
Changing element styling with javascript css.
[et_bloom_locked optin_id=”optin_4″]
Click below to download your preferred Career Guide
Web Developer Career Guide Cloud Career Guide Data Career Guide Robotics Career Guide
[/et_bloom_locked]

IMAGES
VIDEO
COMMENTS
You can do a relative redirect: window.location.href = '../'; //one level up. or window.location.href = '/path'; //relative to domain.
Approach 1: To redirect to a relative URL in JavaScript you can use window.location.href = '/path';. window.location. · Approach 2: To redirect
The window.location object can be used to get information on the current page address (URL). You can also use its method to do a page redirect or refresh...
The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the
The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.
... another webpage with JavaScript. The most popular ones are location.href and location.replace : ... window.location.replace("http://www.w3schools.com");.
replace() does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco. window.location.href
I'm browsing a web app that works fine in Chrome when it does its own changes to window.location but breaks when I do exactly the same commands in Phantom.
The user can be redirected to another webpage with the help of a relative URL by using either the document.location.href property or the window.location.href
The window.location.pathname property returns the path to the given web page on its server. For a URL that contains a domain but no additional