How to get the current URL with JavaScript

0 votes
I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able to grab the full, current URL of the website and set it as a variable to do with.How to do that?
Aug 28, 2020 in Java-Script by kartik
• 37,520 points
1,313 views

1 answer to this question.

0 votes

Hello @kartik,

Use:

window.location.href 

As noted in the comments, the line below works, but it is bugged for Firefox.

document.URL;

Hope it helps!!

Thank You!!

answered Aug 28, 2020 by Niroj
• 82,840 points

Related Questions In Java-Script

0 votes
1 answer

How to get the URL without any parameters in JavaScript?

Hello @kartik, This is possible, but you'll have ...READ MORE

answered Oct 9, 2020 in Java-Script by Niroj
• 82,840 points
7,496 views
+2 votes
1 answer

How to get Session with javascript while loading?

Hello @kartik, Use AJAX to update the view: $(document).ready(function() { ...READ MORE

answered Jun 11, 2020 in Java-Script by Niroj
• 82,840 points
4,158 views
0 votes
1 answer

How to decode the url in php where url is encoded with encodeURIComponent()?

Hello @kartik, Use this function: <?php $string = 'http%3A%2F%2Fexample.com'; $output = ...READ MORE

answered Jul 7, 2020 in Java-Script by Niroj
• 82,840 points
4,465 views
0 votes
1 answer

How to get the file name from a full path using JavaScript?

Hello @kartik, Use this: var filename = fullPath.replace(/^.*[\\\/]/, '') This ...READ MORE

answered Sep 2, 2020 in Java-Script by Niroj
• 82,840 points
1,389 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,090 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,018 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,951 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,894 views
0 votes
1 answer

How to get the host url using javascript from the current page?

Hello @kartik, Use: var host = window.location.hostname; or possibly var host ...READ MORE

answered Oct 9, 2020 in Java-Script by Niroj
• 82,840 points
1,297 views
0 votes
1 answer

How to get the browser to navigate to URL in JavaScript?

Hii, This works in all browsers: window.location.href = '...'; If ...READ MORE

answered May 28, 2020 in Java-Script by Niroj
• 82,840 points
2,692 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP