views:

363

answers:

4

Hi all.

Can I use Internet explorer's "find" to find a number (and go to the first result) in a webpage after I open a new IE window through ASP.NET?

Edit : Maybe I should clarify, I am opening a page on a site that is not mine, I cannot embed and run javascript on it...

Is this even possible?

Thanks Roey

+1  A: 

Not ASP or IE-specific: most sites use highlighting only, which you could also do on the client side using jQuery, like with the Text Highlight plugin.

You would then be missing the "Next" and "Previous" buttons, but I guess someone solved that problem already as well...

EDIT: As you clarified that the content is from some other site: this cannot be done unless you show the content from within your own URL (which is probably not accepted by the owner of the other site). Click for example a Google cache result (for which the content is served from a Google URL) which does do highlighting, while clicking a normal search result (which is served from the site's web server) doesn't do it. That's why Google offers a toolbar that allows for highlighting after all, and that's why people use bookmarklets.

Arjan
A: 

One thing you can do is have your server request the page itself, and then modify the markup with something like jQuery as Arjan mentioned.

With ASP.NET, do something like:

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.siteiwanttofindnumberon.com/pagetoopen.html");
        request.Headers = new WebHeaderCollection();
        //set up headers as necessary
        request.Method = "GET";

        //retrieve the response
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        b = new List<byte>();
        while (b.Count < request.ContentLength)
            b.Add((byte)response.GetResponseStream().ReadByte());

Now you have a List that represents the response stream, as though you'd sent the response yourself with a telnet client or a web browser. You can do as you please with this - for instance, injecting jQuery code to do highlighting for you.

Personally, I would manually scan this list for the information I want and wrap it in a span to highlight it. I would also try to put an in-page anchor at that point and redirect the target of the request to that anchor, thereby forcing the browser to scroll down to the highlighted text. Again, jQuery or another Javascript framework could accomplish this for you as well.

Finally, you'll want to find a way to render this stream to the client. I'm not sure off the top of my head if you can do this in a new window. You may need to manually construct an iFrame-modal-popup type thing, or use an HttpHandler.

JoshJordan
A: 

Even if you had JavaScript access I don't think you could access the Ctrl-F functionality in a browser. Now that you don't even have JS, I guess the answer is no can do...

synhershko
A: 

No, there's no JS-accessible mechanism to do this. There used to be a proprietary IE API for this called NavigateAndFind() but it was removed in IE7 or IE6SP2.

http://msdn.microsoft.com/en-us/library/ms536641(VS.85).aspx

EricLaw -MSFT-