我如何从任何选项卡中的URL中的任何打开的浏览器 [英] How do I get the URLs from any tab in any open browser

查看:228
本文介绍了我如何从任何选项卡中的URL中的任何打开的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想能够检测到网络中的SharePoint用户在看现在。一种方法可以读取浏览器的URL,并尝试将其比作一个参考网址到SharePoint解决方案。我还没能找到在IE和Firefox工程的任何解决方案。

I am trying to detect which web in sharepoint that the user is looking at right now. One approach could be to read the URls from the browser and try to compare them to a reference URL to the sharepoint solution. I have not yet been able to locate any solution that works in both IE and Firefox.

我们的想法是写一个小C#应用程序,将收获的URL并执行比较。

The idea is to write a small C# app that will harvest the URLs and do the comparing.

TIA

推荐答案

这是可能做到这一点在很哈克而且容易使用Win32 API函数FindWindow函数破损道路。

It is possible to do this in a very hacky and prone to breakage way using the Win32 API function FindWindow.

下面的C ++例子,发现Windows计算器的运行实例,并得到编辑字段的值它。你应该能够做到在C#中类似的东西。免责声明:我还没有实际检查,以确保该代码编译,对不起。 :)

The following C++ example that finds a running instance of the windows Calculator and gets the value of the edit field in it. You should be able to do something similar in C#. Disclaimer: I haven't actually checked to make sure this code compiles, sorry. :)

float GetCalcResult(void)
{
    float retval = 0.0f;

    HWND calc= FindWindow("SciCalc", "Calculator");
    if (calc == NULL) {
        calc= FindWindow("Calc", "Calculator");
    }
    if (calc == NULL) {
        MessageBox(NULL, "calculator not found", "Error", MB_OK);
        return 0.0f;
    }
    HWND calcEdit = FindWindowEx(calc, 0, "Edit", NULL);
    if (calcEdit == NULL) {
        MessageBox(NULL, "error finding calc edit box", "Error", MB_OK);
        return 0.0f;
    }

    long len = SendMessage(calcEdit, WM_GETTEXTLENGTH, 0, 0) + 1;
    char* temp = (char*) malloc(len);
    SendMessage(calcEdit, WM_GETTEXT, len, (LPARAM) temp);
    retval = atof(temp);
    free(temp);

    return retval;
}

为了找出正确的参数在FindWindow函数和FindWindowEx,用用在Visual Studio工具间谍++检查你的浏览器窗口的运行实例。对不起,我没有为手头的网络浏览器代码示例,但它应该是可能的。请注意,您的解决方案将是Windows操作系统特有的,也改变了在Web浏览器的未来版本的UI架构可能会导致您的解决方案停止工作。

In order to find out the right parameters to use in FindWindow and FindWindowEx, use the Visual Studio tool Spy++ to inspect a running instance of your browser window. Sorry, I don't have a code sample for web browsers on-hand, but it should be possible. Note that your solution will be Windows OS specific, and also changes to the UI architecture in future versions of the web browsers could cause your solution to stop working.

使用这个方法解除URL右出地址栏的显然只适用于当前选项卡。我看不出这会工作的所有标签页,除非你做了一件很麻烦,想通过标签模拟用户输入周期。这将是非常侵入,并且用户可以通过与自己的输入打断很容易搞砸你的应用程序,但如果你正在写的东西,无人值守运行,就像一个自动化测试脚本它可能工作。如果是这样的话,你可能要考虑其他工具,如 AutoIt的

Using this method to lift the URL right out of the address bar obviously only works for the current tab. I can't see how this would work for all tabs unless you did something really tricky like simulating user input to cycle through the tabs. That would be very intrusive and a user could easily mess up your application by interrupting it with input of their own, but it might work if you're writing something that runs unattended, like an automated test script. If that is the case, you may want to look into other tools like AutoIt.

这建议是所有从博客中转述我曾经写过。祝你好运!

This advice is all paraphrased from a blog post I once wrote. Good luck!

这篇关于我如何从任何选项卡中的URL中的任何打开的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆