• Skip to main content
  • Skip to search
  • Skip to select language
  • Sign up for free
  • English (US)

Window: location property

The Window.location read-only property returns a Location object with information about the current location of the document.

Though Window.location is a read-only Location object, you can also assign a string to it. This means that you can work with location as if it were a string in most cases: location = 'http://www.example.com' is a synonym of location.href = 'http://www.example.com' .

See Location for all available properties.

A Location object.

Basic Example

Example 1: navigate to a new page.

Whenever a new value is assigned to the location object, a document will be loaded using the URL as if location.assign() had been called with the modified URL.

Note that navigation-related sandbox flags may result in an exception being thrown and the navigation failing.

Example 2: Reloading the current page

Consider the following example, which will reload the page by using the replace() method to insert the value of location.pathname into the hash:

Example 4: Display the properties of the current URL in an alert dialog

Example 5: send a string of data to the server by modifying the search property.

The current URL with "?Some%20data" appended is sent to the server (if no action is taken by the server, the current document is reloaded with the modified search string).

Example 6: Using bookmarks without changing the hash property

ā€¦the same thing but with an animated page scroll:

Specifications

Browser compatibility.

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

  • The interface of the returned value, Location
  • A similar information, but attached to the document, Document.location
  • Manipulating the browser history

# 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 assign in jquery

# 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.

Code snippet on HTML abbr Tag

HTML abbr Tag

Code snippet on How to Pad a String with padStart and padEnd in JavaScript

How to Pad a String with padStart and padEnd in JavaScript

Code snippet on Avoid Empty Class in Vue with Null

Avoid Empty Class in Vue with Null

Code snippet on Fix Text Overlap with CSS white-space

Fix Text Overlap with CSS white-space

Code snippet on How to Check if Object is Empty in JavaScript

How to Check if Object is Empty in JavaScript

Learn Java and Programming through articles, code examples, and tutorials for developers of all levels.

  • online courses
  • certification
  • free resources

Friday, July 30, 2021

5 ways to redirect a web page using javascript and jquery, how to redirect a web page using javascript, 1. redirection using window.location.href of javascript, 2. redirection using replace() function, 3. redirection using window assign() function, 4. redirection using navigate function, how to redirect web page using jquery.

10 ways to redirect a web page using JavaScript and jQuery

Great !!!!!

Hi Friend, Do you have any coding to redirect the web page from internet explorer to chrome when i click on a hyperlink

Sorry, you redirect to another site, not another browser, is that possible at all or did I misunderstood your question?

you can also do this with the below example setTimeout(function() { window.location.href = "https://www.google.com/"; }, 0);

How to display msg from php to jQuery page

How to use jQuery response

Hi, I have a question, If i want to redirect another page when i type another webpage, Is it possible from javascript?

Feel free to comment, ask questions if you have any doubt.

Ace your Coding Interview

  • DSA Problems
  • Binary Tree
  • Binary Search Tree
  • Dynamic Programming
  • Divide and Conquer
  • Linked List
  • Backtracking

Redirect to another webpage with JavaScript/jQuery

This post will discuss how to redirect to another webpage in JavaScript and jQuery.

1. Redirecting to another webpage with JavaScript

There are several ways to redirect a page in JavaScript, all of which include the use of the window.location property, which returns a Location object, representing the location (URL) of the current document. To redirect to another webpage with JavaScript, we can use any of the following methods:

1. Using location.href

When we assign a URL to the window.location.href property, the associated document navigates to the new page from the same or different origin. Since window is a global object, window.location.href can be shortened to location.href . Also location is a synonym of location.href , we can directly assign a value to the location object.

2. Using location.assign() function

We can also navigate to a new URL using the location.assign() method. The assign() method loads a new web page by changing the location property. It takes a URL as an argument and replaces the current web page with the new one.

  Note that the assign() method will save the current page in the session history, i.e., the user can go back using the back button. Also if the specified URL is of a different origin, it may fail due to CORS policy.

3. Using location.replace() function

There is another location object method called replace() , which replaces the current document with the document at the specified URL. Unlike the assign() method, this replaces the session History entry, and the user can’t navigate back to the originating page with the back button.

2. Redirecting to another webpage with jQuery

To redirect to another webpage with jQuery, we can assign a URL to href property of the location object using the .prop() or .attr() method. Here is the complete code for redirecting to another webpage with jQuery:

  We can also directly assign a value to the location object.

That’s all about redirecting to another webpage in JavaScript and jQuery.

Refresh/Reload a page with JavaScript/jQuery
Get current URL with JavaScript/jQuery
Setup redirect from HTML page without using JavaScript

Rate this post

Average rating 4.83 /5. Vote count: 41

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Tell us how we can improve this post?

Thanks for reading.

To share your code in the comments, please use our online compiler that supports C, C++, Java, Python, JavaScript, C#, PHP, and many more popular programming languages.

Like us? Refer us to your friends and support our growth. Happy coding :)

window location assign in jquery

Software Engineer | Content Writer | 12+ years experience

guest

  • JS Array Object
  • JS Boolean Object
  • JS Date Object
  • JS Math Object
  • JS Number Object
  • JS String Object
  • JS Reserved Keywords
  • More references

JavaScript Window Location

In this tutorial you will learn about the JavaScript window location object.

The Location Object

The location property of a window (i.e. window.location ) is a reference to a Location object; it represents the current URL of the document being displayed in that window.

Since window object is at the top of the scope chain, so properties of the window.location object can be accessed without window. prefix, for example window.location.href can be written as location.href . The following section will show you how to get the URL of page as well as hostname, protocol, etc. using the location object property of the window object.

Getting the Current Page URL

You can use the window.location.href property to get the entire URL of the current page.

The following example will display the complete URL of the page on button click:

Getting Different Part of a URL

Similarly, you can use other properties of the location object such as protocol , hostname , port , pathname , search , etc. to obtain different part of the URL.

Try out the following example to see how to use the location property of a window.

Note: When you visit a website, you're always connecting to a specific port (e.g. http://localhost:3000). However, most browsers will simply not display the default port numbers, for example, 80 for HTTP and 443 for HTTPS.

Loading New Documents

You can use the assign() method of the location object i.e. window.location.assign() to load another resource from a URL provided as parameter, for example:

You can also use the replace() method to load new document which is almost the same as assign() . The difference is that it doesn't create an entry in the browser's history, meaning the user won't be able to use the back button to navigate to it. Here's an example:

Alternatively, you can use the window.location.href property to load new document in the window. It produce the same effect as using assign() method. Here's is an example:

Reloading the Page Dynamically

The reload() method can be used to reload the current page dynamically.

You can optionally specify a Boolean parameter true or false . If the parameter is true , the method will force the browser to reload the page from the server. If it is false or not specified, the browser may reload the page from its cache. Here's an example:

Note: The result of calling reload() method is different from clicking browser's Reload/Refresh button. The reload() method clears form control values that otherwise might be retained after clicking the Reload/Refresh button in some browsers.

Bootstrap UI Design Templates

Is this website helpful to you? Please give us a like , or share your feedback to help us improve . Connect with us on Facebook and Twitter for the latest updates.

Interactive Tools

BMC

  • Trending Categories

Data Structure

  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

What is the use of window.location in javascript?

Window.location is the location property of a window and it is a reference to a Location object; it represents the current URL of the document being displayed in that window.

Since window object is at the top of the scope chain, so properties of the window.location object can be accessed without window. prefix, for example window.location.href can be written as location.href.

The following section will show you how to get the URL of page as well as hostname, protocol, etc. using the location object property of the window object. You can use the window.location.href property to get the entire URL of the current page.

Windows.location.href property

This is a DOMString containing the entire URL. If changed, the associated document navigates to the new page. It can be set from a different origin than the associated document.

This example of the window.location.href property. In here we are trying to retrieve the URL of the page āˆ’

Windows.location.protocol property

If we click on the button mentioned as ā€˜Get Page URLā€™, we will get the output as current URL. Similarly, you can use other properties of the location object such as protocol, hostname, port, pathname, search, etc. to obtain different part of the URL.

Following is the usage of window.location.protocol property āˆ’

Windows.location.host property

This property represents the host, that is the hostname, a ':', and the port of the URL.

Following example retrieves and prints the host name of the host location in the URL.

The window.location.assign() method

You can use the assign() method of the location object i.e. window.location.assign() to load another resource from a URL provided as parameter. In the example given below we are trying to load new document at the location.

The window.location.replace() method

You can also use the replace() method to load new document which is almost the same as assign(). The difference is that it doesn't create an entry in the browser's history, meaning the user won't be able to use the back button to navigate to it. Following is the example of this method.

Abdul Rawoof

Related Articles

  • How to use window.location to redirect to a different URL with JavaScript?
  • What is the use of Map in JavaScript?
  • What is the use of Atomics in JavaScript?
  • What is the use of OBJECT.assign() in javascript?
  • What is the use of sentry in javascript?
  • What is the use of JavaScript cookies?
  • What is the use of declaring variables in JavaScript?
  • What is the use of proxy() object in JavaScript?
  • What is the use of Atomics.store() method in JavaScript?
  • What is the use of Object.isFrozen() method in JavaScript?
  • What is the use of apply() function in JavaScript?
  • What is the use of Math.hypot() function in JavaScript?
  • What is the use of _.size() method in JavaScript?
  • What is the use of parsing dates in JavaScript?
  • What is the use of test() method in JavaScript?

Kickstart Your Career

Get certified by completing the course

  • 90% Refund @Courses
  • DSA with JS - Self Paced
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Operator
  • JS Projects
  • JS Cheat Sheet
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
  • JS Web Technology

Related Articles

  • Solve Coding Problems
  • JavaScript Getters and Setters
  • JavaScript Object Reference
  • JavaScript Object initializer
  • JavaScript Object.prototype.constructor Property
  • How to get the Class Name of an Object in JavaScript
  • JavaScript History object
  • Prototype in JavaScript
  • JavaScript Objects
  • How to iterate over a JavaScript object ?
  • Remove blank attributes from a JavaScript Object
  • JavaScript Object isPrototypeOf() Method
  • How to merge properties of two JavaScript objects dynamically?
  • How to use forEach with an Array of Objects in JavaScript ?
  • Find the length of a JavaScript object
  • Creating objects in JavaScript (4 Different Ways)
  • How to use a variable for a key in a JavaScript object literal?
  • How to get the last item of JavaScript object ?
  • How to get a key in a JavaScript object by its value ?
  • How to add a property to a JavaScript object using a variable as the name?

JavaScript | window.location and document.location Objects

  • The window.location is read/write on all compliant browsers.
  • The document.location is read-only in Internet Explorer but read/write in Firefox, SeaMonkey that are Gecko-based browsers.
  • window.location.href: It returns the URL of the current working page.
  • window.location.hostname: It returns the domain name of web host.
  • window.location.pathname: It returns the path and filename of the current working page.
  • window.location.protocol: It returns the used protocol (http: or https:).
  • window.location.port(): It prints the port number.
  • window.location.host(): It prints host name along with port number.
  • window.location.assign(): It loads new document.

window location assign in jquery

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now !

Please Login to comment...

  • javascript-object
  • Web Technologies

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Javatpoint Logo

JavaScript Tutorial

Javascript basics, javascript objects, javascript bom, javascript dom, javascript validation, javascript oops, javascript cookies, javascript events, exception handling, javascript misc, javascript advance, differences.

Interview Questions

JavaTpoint

  • Send your Feedback to [email protected]

Help Others, Please Share

facebook

Learn Latest Tutorials

Splunk tutorial

Transact-SQL

Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial

Preparation

Aptitude

Verbal Ability

Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

RSS Feed

The Window Location Object

The assign property.

window.location.href is not a function Error in JavaScript

avatar

Last updated: Dec 30, 2022 Reading time Ā· 2 min

banner

# window.location.href is not a function Error in JavaScript

The "window.location.href is not a function" error occurs when we try to invoke the href property on the window.location object.

To solve the error, use the assign method on the window.location property.

window location href is not a function

Here is an example of how the error occurs.

And this is the code in our index.js file.

We tried to invoke the href property as a function, so the error occurred.

Instead, you should use the window.location.assign method.

The window.location.assign method enables us to navigate to a new page.

You could achieve the same result if you assign a string to the window.location.href property.

If you load the page and click on the button, you will navigate to the webpage you assigned to the property.

If you need to check out all of the properties on the location object, here is a link from the MDN docs .

Similar methods to assign include:

  • window.location.reload() - reloads the current URL (like the refresh button).
  • window.location.replace() - redirects to the provided URL. The difference from the assign() method is that when using the replace() method, the current page is not saved in the session history, so users are not able to use the back button to navigate to it.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

  • Check if a Window or a Browser Tab has Focus in JavaScript
  • ReferenceError: window is not defined in JavaScript [Solved]
  • How to use 'mailto' in JavaScript [4 Easy Ways]

book cover

Borislav Hadzhiev

Web Developer

buy me a coffee

Copyright Ā© 2024 Borislav Hadzhiev

TalkersCode Website Logo

All TalkersCode Topics

window location assign in jquery

Follow TalkersCode On Social Media

window location assign in jquery

devloprr.com - A Social Media Network for developers Join Now ➔

window.location.href jQuery

Last Updated : Jul 1, 2023

IN - jQuery | Written & Updated By - Ashish

window.location.href jQuery

In this article we will show you the solution of window.location.href jQuery, the domain name or web address of a company website may occasionally change.

However, you'll attempt to log in there if you just have knowledge of the prior version of the website, isn't that right? Consider that you wish to go to ABC.com.

However, xyz.com had sadly become the new address. Your browser will immediately reroute you to the website's current address.

There are numerous methods for redirecting a web page using JavaScript.

The various techniques for rerouting a web page are listed in this article. Now move to the concept of window.location.href in jquery.

Step By Step Guide On window.location.href jQuery :-

Taking a user to a new place is what is meant by redirecting a web page.

A lot of websites utilise redirects for a variety of purposes, including Some websites switch visitors from the previous domain to the new one, while others switch users through one page to another, perhaps one that is more pertinent.

SendRedirect and Forward techniques are used in web applications to reroute users, thus if you’re a Java programmer and have experience with Servlet and JSP, you may be familiar with them.

Redirecting can be done in two ways: server-side and client-side. While a client-side redirect is initiated by the client code, a server-side redirect is started by the server.

A client-side redirection is when a web page is changed using JavaScript and JQuery.

To make a page redirect, only utilise the JavaScript window.location property; jQuery is not required.

The syntax window.location.replace("page url") can be used to instantly reroute the user from one page to another.

The advantage in this situation is that the replace() technique avoids the user from being routed towards the destination page again since it does not will save originating page inside the session history.

As a result, the user cannot access it using the browser's back button.

How to use JavaScript to reroute a website

Let's first discover well how redirect the web page using standard JavaScript before we examine the jQuery code.

It offers a number of straightforward methods to complete this work without requiring the loading of an external Javascript like jQuery.

1. Redirection using window.location.href of Javascript

The simplest method of redirecting a URL with JavaScript is to simply change the window's href attribute.location thing.

This duplicates the process of entering a new page normally. Simply assigning a new URL is the easiest task I can think of.

It's important to remember that window.location.href sometimes makes a call to the server and sometimes loads the page from the browser's cache.

Therefore, this will redirect to that page rather than loading a new one from the server if you have an outdated version of a page accessible in the cache.

2. Using the replace() function for redirection

To use the replace() method of a window.location object is another approach to use jQuery's redirection feature to go to a certain web page.

With this technique, the current URL is replaced with a new URL and removed from the history.

If you want simply redirect to such a new page and prevent the user from using the back button to return to the previous page, use the replace() method.

3. Using the window assign() function, redirection

JavaScript's window.location.assign() technique can also be used to reroute a web page.

This function, unlike replace(), adds an additional URL to the previous stack and redirects to the new URL, allowing you to click the back button to return to the initial document.

If you want to let the user utilise the back button to return to the original document, just use assign() method for redirection.

4. Use of the navigate function for redirection

This feature is equivalent to window.location="url" and it gets a page from the cache rather than just simply accessing it directly from the server.

How to use jQuery to redirect a web page

With just single line of code, you may also redirecting the web page to some other URL using the jQuery API.

Even if this is not the best approach to use jQuery, since everyone uses it differently in some kind of a web project, still is sensible to take advantage of it for whatever function we can.

Using JavaScript's attr() as opposed to window.location.href has a small difference.

Window.location.href serves pages from the cache whereas $(location).attr('href', url) requests a new page from the server.

  • With the aid of HTML & HEAD tags, we begin our coding.
  • Following that, we give our page's title.
  • Next, we begin writing the actual code.
  • Next, we use script to import the jQuery library.
  • We then begin our script.
  • After that, we run the jQuery code using the ready() method.
  • Next, we give the website's url that we want to redirect.
  • Next, we employ location.
  • With the SCRIPT, BODY, and HTML elements, we finish our code.

Conclusion :-

As a result, we were able to learn about window.locatio.href in jQuery. We also learned how to use JavaScript and jQuery to redirecting a web request to a different web page.

As you can see, there are several techniques to divert traffic, but each one differs slightly.

For example (location). Javascript's window.location.href fetches pages from cache, whereas jQuery's attr('href', url) call opens a new page from the server.

I hope this article on window.location.href jQuery helps you and the steps and method mentioned above are easy to follow and implement.

About Ashish

Ashish is a dynamic and motivated individual with a passion of programming and an experienced programmer having 3+ years of experience in various languages like Java, Python, HTML, CSS, JavaScript, jQuery and various frameworks like Bootstrap

Follow Ashish On Linkedin 🡪

Latest Articles

POPULAR TUTORIALS

Python Capitalize First Letter Of Every Word In String

Become a Full-Stack Web Developer with just ONE course

  • ✓ Front-End Web Development
  • ✓ Backend Web Development
  • ✓ HTML 5 & CSS 3
  • ✓ Bootstrap 4
  • ✓ Javascript & jQuery
  • ✓ Node.js
  • ✓ React.js
  • ✓ MongoDB
  • ✓ And 20+ More

Bestseller Course with 4.7 ★ ★ ★ ★ ☆ rating Available In English & 14+ More Languages

Latest Tutorials

ABOUT TalkersCode ❯

TalkersCode is one of the best and biggest website for web developers in India. We have tutorials, demos, products reviews & offers for web developers & designers

AFFILIATE DISCLOSURE ❯

We as TalkersCode may receive compensation from some of the companies whose products we review.

USEFUL LINKS ❯

  • PRIVACY POLICY

© 2024 All Rights Reserved To TalkersCode.com

window location assign in jquery

Create a form in Word that users can complete or print

In Word, you can create a formĀ that others can fill out and saveĀ or print.Ā  To do this, you will start with baseline content in a document, potentiallyĀ viaĀ a form template.Ā  Then you can add content controls for elements such as check boxes, text boxes, date pickers, and drop-down lists. Optionally, these content controls canĀ be linked to database information.Ā  Following are the recommended action steps in sequence.Ā Ā 

Show the Developer tab

In Word, be sure youĀ haveĀ the Developer tabĀ displayed in the ribbon.Ā  (See how here:Ā  Show the developer tab .)

Open a template or a blank document on which to base the form

You can start with aĀ templateĀ or just start from scratch with a blank document.

Start with a form template

Go to File > New .

In theĀ  Search for online templates Ā field, typeĀ  Forms or the kindĀ of form you want. ThenĀ press Enter .

In the displayed results, right-click any item, thenĀ selectĀ  Create.Ā 

Start with a blank documentĀ 

Select Blank document .

Add content to the form

Go to theĀ  Developer Ā tab Controls section where you canĀ choose controls to add to yourĀ document or form. Hover over any iconĀ therein to see what control type it represents.Ā TheĀ various control types are described below. You can set properties on a controlĀ once it has been inserted.

To delete a content control, right-click it,Ā thenĀ select Remove content controlĀ  in the pop-up menu.Ā 

Note:Ā  You can print a form that was created viaĀ content controls. However, the boxes around the content controls will not print.

Insert a text control

The rich text content control enablesĀ users to format text (e.g., bold,Ā italic)Ā and type multiple paragraphs. To limit these capabilities, useĀ the plain text content control .Ā 

Click or tap where you want to insert the control.

Rich text control button

To learn about setting specific properties on these controls, see Set or change properties for content controls .

Insert a picture control

A picture control is most often used for templates, but you can also add a picture control to a form.

Picture control button

Insert a building block control

Use a building block control Ā when you want users to choose a specific block of text. These are helpful when you need to add different boilerplate text depending on the document'sĀ specific purpose. You can create rich text content controls for each version of the boilerplate text, and thenĀ use a building block control as the container for the rich text content controls.

building block gallery control

Select Developer and content controls for the building block.

Developer tab showing content controls

Insert a combo box or a drop-down list

In a combo box, users can select from a list of choices that you provide or they can type in their own information. In a drop-down list, users can only select from the list of choices.

combo box button

Select the content control, and then select Properties .

To create a list of choices, select Add under Drop-Down List Properties .

Type a choice in Display Name , such as Yes , No , or Maybe .

Repeat this step until all of the choices are in the drop-down list.

Fill in any other properties that you want.

Note:Ā  If you select the Contents cannot be edited check box, users wonā€™t be able to click a choice.

Insert a date picker

Click or tap where you want to insert the date picker control.

Date picker button

Insert a check box

Click or tap where you want to insert the check box control.

Check box button

Use the legacy form controls

Legacy form controls are for compatibility with older versions of Word and consist of legacy form and Active X controls.

Click or tap where you want to insert a legacy control.

Legacy control button

Select the Legacy Form control or Active X Control that you want to include.

Set or change properties for content controls

Each content control has properties that you can set or change. For example, the Date Picker control offers options for the format you want to use to display the date.

Select the content control that you want to change.

Go to Developer > Properties .

Controls Properties  button

Change the properties that you want.

Add protection to a form

If you want to limit how much others can edit or format a form, use the Restrict Editing command:

Open the form that you want to lock or protect.

Select Developer > Restrict Editing .

Restrict editing button

After selecting restrictions, select Yes, Start Enforcing Protection .

Restrict editing panel

Advanced Tip:

If you want to protect only parts of the document, separate the document into sections and only protect the sections you want.

To do this, choose Select Sections in the Restrict Editing panel. For more info on sections, see Insert a section break .

Sections selector on Resrict sections panel

If the developer tab isn't displayed in the ribbon, see Show the Developer tab .

Open a template or use a blank document

To create a form in Word that others can fill out, start with a template or document and add content controls. Content controls include things like check boxes, text boxes, and drop-down lists. If youā€™re familiar with databases, these content controls can even be linked to data.

Go to File > New from Template .

New from template option

In Search, type form .

Double-click the template you want to use.

Select File > Save As , and pick a location to save the form.

In Save As , type a file name and then select Save .

Start with a blank document

Go to File > New Document .

New document option

Go to File > Save As .

Go to Developer , and then choose the controls that you want to add to the document or form. To remove a content control, select the control and press Delete. You can set Options on controls once inserted. From Options, you can add entry and exit macros to run when users interact with the controls, as well as list items for combo boxes, .

Adding content controls to your form

In the document, click or tap where you want to add a content control.

On Developer , select Text Box , Check Box , or Combo Box .

Developer tab with content controls

To set specific properties for the control, select Options , and set .

Repeat steps 1 through 3 for each control that you want to add.

Set options

Options let you set common settings, as well as control specific settings. Select a control and then select Options to set up or make changes.

Set common properties.

Select Macro to Run on lets you choose a recorded or custom macro to run on Entry or Exit from the field.

Bookmark Set a unique name or bookmark for each control.

Calculate on exit This forces Word to run or refresh any calculations, such as total price when the user exits the field.

Add Help Text Give hints or instructions for each field.

OK Saves settings and exits the panel.

Cancel Forgets changes and exits the panel.

Set specific properties for a Text box

Type Select form Regular text, Number, Date, Current Date, Current Time, or Calculation.

Default text sets optional instructional text that's displayed in the text box before the user types in the field. Set Text box enabled to allow the user to enter text into the field.

Maximum length sets the length of text that a user can enter. The default is Unlimited .

Text format can set whether text automatically formats to Uppercase , Lowercase , First capital, or Title case .

Text box enabled Lets the user enter text into a field. If there is default text, user text replaces it.

Set specific properties for a Check box .

Default Value Choose between Not checked or checked as default.

Checkbox size Set a size Exactly or Auto to change size as needed.

Check box enabled Lets the user check or clear the text box.

Set specific properties for a Combo box

Drop-down item Type in strings for the list box items. Press + or Enter to add an item to the list.

Items in drop-down list Shows your current list. Select an item and use the up or down arrows to change the order, Press - to remove a selected item.

Drop-down enabled Lets the user open the combo box and make selections.

Protect the form

Go to Developer > Protect Form .

Protect form button on the Developer tab

Note:Ā  To unprotect the form and continue editing, select Protect Form again.

Save and close the form.

Test the form (optional)

If you want, you can test the form before you distribute it.

Protect the form.

Reopen the form, fill it out as the user would, and then save a copy.

Creating fillable forms isnā€™t available in Word for the web.

You can create the form with the desktop version of Word with the instructions in Create a fillable form .

When you save the document and reopen it in Word for the web, youā€™ll see the changes you made.

Facebook

Need more help?

Want more options.

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

window location assign in jquery

Microsoft 365 subscription benefits

window location assign in jquery

Microsoft 365 training

window location assign in jquery

Microsoft security

window location assign in jquery

Accessibility center

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

window location assign in jquery

Ask the Microsoft Community

window location assign in jquery

Microsoft Tech Community

window location assign in jquery

Windows Insiders

Microsoft 365 Insiders

Was this information helpful?

Thank you for your feedback.

IMAGES

  1. How to Effectively Use window.location in jQuery

    window location assign in jquery

  2. JavaScript

    window location assign in jquery

  3. jQuery : window.location.search query as JSON

    window location assign in jquery

  4. jQuery : Add window.location to body class

    window location assign in jquery

  5. jQuery Window Manager

    window location assign in jquery

  6. JavaScript Training Tutorial Window Location ASSIGN() Method

    window location assign in jquery

COMMENTS

  1. Location: assign() method

    Location: assign () method. The assign () method of the Location interface causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.assign () by pressing the "back" button.

  2. Location assign() Method

    See Also: The replace() Method. Note. The difference between assign() and replace(): replace() removes the current URL from the document history. With replace() it is not possible to use "back" to navigate back to the original document.

  3. pass post data with window.location.href

    Pull out all their values, dynamically build a form with all of the fields in all three forms, and submit that form. The form can be invisible. Don't use a JQuery AJAX method, use $("#myForm").submit().The form- which will be invisible, and only used to submit values from your client side code, not user input- will never be shown nor otherwise used, and the page will be refreshed.

  4. JavaScript Window Location

    Window Location. The window.location object can be written without the window prefix.. Some examples: window.location.href returns the href (URL) of the current page; window.location.hostname returns the domain name of the web host; window.location.pathname returns the path and filename of the current page; window.location.protocol returns the web protocol used (http: or https:)

  5. Window: location property

    Window: location property. The Window.location read-only property returns a Location object with information about the current location of the document. Though Window.location is a read-only Location object, you can also assign a string to it. This means that you can work with location as if it were a string in most cases: location = 'http ...

  6. Window Location Object

    Learn jQuery Tutorial Reference Learn Vue ... window.location or just location. Examples. let origin = window.location.origin; ... assign() Loads a new document: reload() Reloads the current document: replace() Replaces the current document with a new one

  7. window.location Cheatsheet

    # 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:

  8. Difference between window.location.href, window.location.replace and

    window.location.assign Property:. The assign function is similar to the href property as it is also used to navigate to a new URL.; The assign method, however, does not show the current location, it is only used to go to a new location. Unlike the replace method, the assign method adds a new record to history (so that when the user clicks the "Back" button, he/she can return to the current ...

  9. 5 ways to redirect a web page using JavaScript and jQuery

    2. Redirection using replace () function. Another way to redirect to a web page in jQuery is by using the replace () function of the window.location object. This method removes the current URL from the history and replaces it with a new URL. Here is an example of how to use this function for redirection:

  10. Redirect to another webpage with JavaScript/jQuery

    1. Using location.href. When we assign a URL to the window.location.href property, the associated document navigates to the new page from the same or different origin. Since window is a global object, window.location.href can be shortened to location.href. Also location is a synonym of location.href, we can directly assign a value to the ...

  11. JavaScript Window Location

    The location property of a window (i.e. window.location) is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window.location object can be accessed without window. prefix, for example window.location.href can ...

  12. javascript

    So in the code you indicated you are changing the href property of the DOM object location, using a jQuery style. - Adriano G. V. Esposito Mar 17, 2020 at 10:40

  13. What is the use of window.location in javascript?

    The window.location.assign() method. You can use the assign() method of the location object i.e. window.location.assign() to load another resource from a URL provided as parameter. In the example given below we are trying to load new document at the location. Example <!

  14. JavaScript

    All modern browsers map document.location to the window.location but you can prefer window.location for cross-browser safety. Syntax: window.location.href: It returns the URL of the current working page. window.location.hostname: It returns the domain name of web host. window.location.pathname: It returns the path and filename of the current ...

  15. Window Location in JavaScript

    The location object includes a page's URL. It can be accessed using window.location or document.location. The Location object has characteristics that represent the URL, such as protocol, pathname,host, and search. To manipulate the location, set its properties and use assign(), replace(), and reload().

  16. javascript

    If you change the url, you will force the browser to try to request that url server side. You cannot just change the URL in spirit. Best you could do is change the #hash part of the url if you use it. - MooGoo

  17. W3Schools Tryit Editor

    The W3Schools online code editor allows you to edit code and view the result in your browser

  18. window.location.href is not a function Error in JavaScript

    If you need to check out all of the properties on the location object, here is a link from the MDN docs. Similar methods to assign include: window.location.reload() - reloads the current URL (like the refresh button). window.location.replace() - redirects to the provided URL.

  19. window.location.href jQuery

    The simplest method of redirecting a URL with JavaScript is to simply change the window's href attribute.location thing. This duplicates the process of entering a new page normally. Simply assigning a new URL is the easiest task I can think of. It's important to remember that window.location.href sometimes makes a call to the server and ...

  20. How to add target="_blank" to JavaScript window.location?

    window.location sets the URL of your current window. ... Including target _blank in jquery location.href-1. How to give target_blank for an input type submit and onclick javascript function. 0. Open specific JS in new tab. 0. target _blank not working with download attribute. Related. 2.

  21. Create a form in Word that users can complete or print

    Show the Developer tab. If the developer tab isn't displayed in the ribbon, see Show the Developer tab.. Open a template or use a blank document. To create a form in Word that others can fill out, start with a template or document and add content controls.

  22. jquery

    var query = window.location.search.sub... Stack Overflow. About; Products For Teams; Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; ... Jquery get window.location.search tag in array. 0. Javascript location.search. 0. Adding a simple search function to ...