ASP.NET打开新的IE窗口并以编程方式运行“查找”?

时间:2022-06-09 21:16:17

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?

在通过ASP.NET打开新的IE窗口后,我可以使用Internet Explorer的“查找”来查找网页中的数字(并转到第一个结果)吗?

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...

编辑:也许我应该澄清,我在一个不是我的网站上打开一个页面,我无法嵌入并运行javascript ...

Is this even possible?

这甚至可能吗?

Thanks Roey

4 个解决方案

#1


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.

不是ASP或IE特定的:大多数网站只使用突出显示,你也可以在客户端使用jQuery,就像使用Text Highlight插件一样。

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.

编辑:当您澄清内容来自其他某个站点时:除非您在自己的URL中显示内容(可能不被其他站点的所有者接受),否则无法执行此操作。点击例如Google缓存结果(其内容由Google网址提供),该结果会突出显示,而点击正常搜索结果(从网站的网络服务器提供)则不会这样做。这就是为什么Google提供了一个允许突出显示的工具栏,这就是人们使用bookmarklet的原因。

#2


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.

您可以做的一件事是让您的服务器请求页面本身,然后使用像Arjan提到的jQuery之类的东西来修改标记。

With ASP.NET, do something like:

使用ASP.NET,执行以下操作:

        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.

现在您有一个表示响应流的List,就像您使用telnet客户端或Web浏览器自己发送了响应一样。你可以随意做这件事 - 例如,注入jQuery代码为你做突出显示。

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.

就个人而言,我会手动扫描此列表以获取我想要的信息,并将其包装在一个范围内以突出显示它。我还会尝试在该点放置一个页内锚点,并将请求的目标重定向到该锚点,从而强制浏览器向下滚动到突出显示的文本。同样,jQuery或其他Javascript框架也可以为您完成此任务。

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.

最后,您需要找到一种方法将此流呈现给客户端。如果你能在新窗口中做到这一点,我不确定是不是最重要的。您可能需要手动构建iFrame-modal-popup类型的东西,或使用HttpHandler。

#3


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...

即使您有JavaScript访问权限,我也不认为您可以在浏览器中访问Ctrl-F功能。既然你甚至没有JS,我想答案是不行的......

#4


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.

不,没有JS可访问的机制来执行此操作。曾经有一个名为NavigateAndFind()的专有IE API,但在IE7或IE6SP2中删除了它。

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

#1


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.

不是ASP或IE特定的:大多数网站只使用突出显示,你也可以在客户端使用jQuery,就像使用Text Highlight插件一样。

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.

编辑:当您澄清内容来自其他某个站点时:除非您在自己的URL中显示内容(可能不被其他站点的所有者接受),否则无法执行此操作。点击例如Google缓存结果(其内容由Google网址提供),该结果会突出显示,而点击正常搜索结果(从网站的网络服务器提供)则不会这样做。这就是为什么Google提供了一个允许突出显示的工具栏,这就是人们使用bookmarklet的原因。

#2


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.

您可以做的一件事是让您的服务器请求页面本身,然后使用像Arjan提到的jQuery之类的东西来修改标记。

With ASP.NET, do something like:

使用ASP.NET,执行以下操作:

        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.

现在您有一个表示响应流的List,就像您使用telnet客户端或Web浏览器自己发送了响应一样。你可以随意做这件事 - 例如,注入jQuery代码为你做突出显示。

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.

就个人而言,我会手动扫描此列表以获取我想要的信息,并将其包装在一个范围内以突出显示它。我还会尝试在该点放置一个页内锚点,并将请求的目标重定向到该锚点,从而强制浏览器向下滚动到突出显示的文本。同样,jQuery或其他Javascript框架也可以为您完成此任务。

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.

最后,您需要找到一种方法将此流呈现给客户端。如果你能在新窗口中做到这一点,我不确定是不是最重要的。您可能需要手动构建iFrame-modal-popup类型的东西,或使用HttpHandler。

#3


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...

即使您有JavaScript访问权限,我也不认为您可以在浏览器中访问Ctrl-F功能。既然你甚至没有JS,我想答案是不行的......

#4


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.

不,没有JS可访问的机制来执行此操作。曾经有一个名为NavigateAndFind()的专有IE API,但在IE7或IE6SP2中删除了它。

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