Open current page in new window including query string
Here goes: I have an application that does some processing, writes some result files and then displays the results in an embedded IE browser control. This is done by navigating the browser control to a local HTML file together with a query string containing the generated result files to display it all. The link target would look som开发者_StackOverflowething like:
c:\SomeFolder\results.htm?results=file%201.xml;file%202.xml;file%203.xml
So far, everything's fine. However, in the HTML page is a href that is suppossed to open up the exact same just in a normal browser window.
What I thought would work is:
<a href="#" target="_blank">Show in browser</a>
Since it is a link in an HTML page displayed in an IE control, the link will open up in IE no matter what the default browser might be. This works for IE7 and 8, but not for IE6. With IE6 the query string gets cut off and the browser opens
file://c:/results/results.htm#
without the query string.
I am sure there must be a much better way to do this without the #
and which would work in all IEs.
How would the pros solve this?
This should work:
<a href="javascript://;" onclick="this.href=document.location" target="_blank">Show in browser</a>
I would;
<a href="yourpage.html" target="_blank" onclick="return !window.open(location.href, this.target);">Show in browser</a>
(The 'yourpage.html' in the anchor is to satisfy the fact that an anchor should have an href, it would only be loaded if the window.open() failed)
精彩评论