0

I am looking for a way to use Jquery (or any other open source script) to pull the URL of a particular webpage. I am working on a service that will pull the original URL of any webpage - consider a scenario where I load google.com but have entered yahoo.com in the address bar (without pressing enter key) - the script should be able to validate if the the URL on the address bar is the same as the actual URL or if it is different.

2
  • What do you want to achieve get the URL of the current page or get the value of the address bar? The former is possible the latter is not. Commented Feb 8, 2014 at 7:27
  • @Vishal "validate if the the URL on the address bar is the same as the actual URL" Commented Feb 8, 2014 at 7:34

4 Answers 4

2

There is no way to do this. And there better not be any in the making. There is no reason to need such information, and it's a violation of user privacy.

Sign up to request clarification or add additional context in comments.

Comments

2

No dear, Absolutely no way to do this.

and i agree with @bjb568 , its definitely violation of user privacy.

you can get the current page URL in your script.

But why you need this kind of functionality.?

i will advise you to find any alternative of your requirement,

1 Comment

I can make do without pulling the address bar URL. But any idea how I should pull the URL of the webpage in question? Also, this shall be a user-triggered function - so I will not pull this data unless requested by the user. So I hope there would not be any privacy concerns because of this.
1

You can get the current location of the page using regular Javascript, but I do not think you can get the currently typed address bar, although I do not see where you should ever need to.

In response to everyone on here saying it is a breach of user privacy: I don't think grabbing the URL or the typed address bar on the current page is a breach of privacy or security unless you are somehow able to change the address bar to make it seem like you are on a different site - like being on Google.com and it saying you are on Yahoo.com. But, from the OP's original question, it just seems like he wants to get the information; not change it.

Using Javascript, you can use var location = document.location.href

The closest you can get to change the addressbar is window.history.pushState(), but browsers have a security settings that do not allow domains outside of the current domain to be used.

Comments

0

My first question that comes to mind: "Why on earth does he want to do that???" If it was possible you would have to interact with each browser directly which is not possible.

jQuery is just a client-language that interprets with each browsers "engine" (that handles rendering of html, javascript etc) and not the browser itself (menus, settings etc). Secondly, if it would work: How often would you check? Each keypress? Every 10 seconds? It would not be doable in a proper way - even if it was possible.

I think you should rethink your issue and try to explain why you want to do this. It might be other (better) solutions that would handle your issue in a better way.

7 Comments

This does not answer the question, such details should be mentioned as comments. There are very good security reasons why you don't allow address bar access through Javascript that have nothing to do with implementation. Although this functional is not available on popular browsers, I would not be surprised if it was available on at least some of them. It would also be easy to implement if someone required this functionality for whatever reason.
@Vishal - there might some browsers that offers this functionality but my point of view is that the target market is about the mainstream/popular browswers. It's no reason why it shouldn't be. You're right, it maybe should have posted as a comment instead...
"It's no reason why it shouldn't be." You are creating a Q&A resource, this answer should be modified to provide relevant explanation about why popular web browsers don't have this functionality and why this functionality is not part of any ECMA Script standard.
To get the actual (full) url - take a peak at this: stackoverflow.com/questions/6768793/get-the-full-url-in-php
@Vishal - no I don't think I have to explain why this functionality doesn't exist in modern browsers - essaentially because that was not the question. I really answered the question as good as anybody as else who's answered it: "There is no way to do this" (previous answers). If you want to, you could of course improve my answer - if you think it's needed.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.