Intercepting URL before navigation

孤街醉人 提交于 2019-12-13 00:40:47

问题


I would like to intercept any URL which the user enters in their browser and perform some tasks before allowing the navigation to continue (any way could be good - i.e. via plug in, via proxy or any other creative suggestion). To clarify - I am not referring to a specific application that needs to catch this, but rather - any navigation that the user does on his browser needs to be caught (i.e. the user is not opening my application, it should be running in the background or something like that...) Thanks in advance...


回答1:


I do not think you can "intercept" what the user enters via javascript. It smells like a big security exploit. You can detect when the user leaves the page, but you cannot detect where he is going next.

  • A proxy is a good choice if you just need the URL string to be processed. But anything more complex will be complicated to implement in a proxy.

  • A plugin however, depends on which browser you are targetting, you can't make a single plugin that targets all browser and control user navigation at the same time. But if you get to selects which browser your user uses, then maybe.

  • How about rolling your own browser (using IE's ActiveX control) or using one of the open source alternatives and use that?

What exact processing is it that you wish to do?




回答2:


If you're using Javascript, there's an event which fires when the user exists a page called onunload.

window.onunload = function() {
    alert("You're leaving this page.");
};



回答3:


You could create a hidden frame which would add a watch to the window.location object of the main frame. I'm not sure if you can use watches in IE - if not, you may need to just periodically poll the other window to see what page it's on.

If the user types an address in the browser window, then you can't capture that (since your frame will be removed), but you'll get all the links they click on (even to external sites).




回答4:


You may want to have a look at Fiddler:

... Web Debugging tool that enables capture, replay, and modification of HTTP and HTTPS traffic from virtually any application.

From what I understand it acts as a lightweight proxy which can do all sorts of cool stuff as defined by a .NET script.

You can also set it up such that you can run mobile devices through it, if that's of interest to you.



来源:https://stackoverflow.com/questions/277178/intercepting-url-before-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!