Open link in same browser tab

2020-02-15 06:59发布

问题:

How do I open a link in the same browser tab? I tried this code:

ShellExecute(Handle, 'open', 'http://site.com', '_self', nil, SW_SHOWNORMAL);

But it continues to open the link in a new table.

Thanks.

回答1:

I've written on this topic before:

ShellExecute has absolutely no notion of "tab." In fact, it doesn't even have a notion of "default browser." All it does is find whatever program is configured for file names that start with "http://" and execute the configured command line.

What the browser does with the new command line is its own choice. The API function has no control. Sometimes, the browser allows the user to configure it.

Opening a new tab or window is the safest thing to do. Neither you nor the browser knows whether the user is still using the previous tab or window.



回答2:

A possible entry point is using OLE Automation. Using this technique you can connect with any existing instance of MSIE, so that you can bring the current browsing window to a new url.