Getting active tab url from Safari

感情迁移 提交于 2019-12-11 23:13:19

问题


I am trying to get the active tab url for Safari, so far I was able to get the url from all prominent browsers (IE, Firefox, Chrome, Opera) through a mix of Win32 API calls or DDE.

The issue with safari is even when I enumerate through the windows and call GetWindowText it's always null.

Any solutions out there? thanks!


回答1:


public static string getChromeURL() {
  uint MAX_PATH=255;
  IntPtr hChrome, hAddressBox;

  hChrome=GetForegroundWindow();
  hAddressBox = FindWindowEx(hChrome, IntPtr.Zero,
            "Chrome_AutocompleteEditView", IntPtr.Zero);

  StringBuilder sb = new StringBuilder(256);
  SendMessage(hAddressBox, WM_GETTEXT, (IntPtr)MAX_PATH, sb);

  string s = sb.ToString().Trim(new Char[] { ' ', '\0', '\n' });
  return s;
}


来源:https://stackoverflow.com/questions/5041141/getting-active-tab-url-from-safari

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