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.

Anand
  • 63
  • 10
  • 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. – Vishal Feb 08 '14 at 07:27
  • @Vishal "validate if the the URL on the address bar is the same as the actual URL" – bjb568 Feb 08 '14 at 07:34

4 Answers4

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.

bjb568
  • 11,089
  • 11
  • 50
  • 71
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,

Mitul Maheshwari
  • 2,647
  • 4
  • 24
  • 38
  • 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. – Anand Feb 08 '14 at 09:08
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.

SyntaxLAMP
  • 975
  • 8
  • 11
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.

bestprogrammerintheworld
  • 5,417
  • 7
  • 43
  • 72
  • 1
    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 Feb 08 '14 at 08:17
  • 1
    @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... – bestprogrammerintheworld Feb 08 '14 at 08:33
  • "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. – Vishal Feb 08 '14 at 09:01
  • @bestprogrammerintheworld : So if I change the requirement to just be able to pull the original URL of the webpage and display it, would it be possible? In that case, how do I enable it? Also, this shall be a user-triggered event. So the user will be absolutely aware of the consequences of pressing the button. – Anand Feb 08 '14 at 09:11
  • 1
    To get the actual (full) url - take a peak at this: http://stackoverflow.com/questions/6768793/get-the-full-url-in-php – bestprogrammerintheworld Feb 08 '14 at 11:08
  • If you want the user to be fully aware of the consequences of hitting the button you would have another page where you do some confirmation, alternatively just add a checkbox with a link to some kind of agreement. For this you don't have to pull the actual url. If you explain exactly what you're trying to achieve and some kind of example it would really help giving you (probably) a better answer. – bestprogrammerintheworld Feb 08 '14 at 11:14
  • 1
    @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. – bestprogrammerintheworld Feb 08 '14 at 11:23