Silverlight 4 OOB应用程序访问WebBrowser控件中页面的HTML DOM

发布于 2024-08-29 18:14:13 字数 216 浏览 10 评论 0原文

有谁知道是否可以访问和操作由 Silverlight 4 WebBrowser 控件呈现的 html 页面中的元素。

场景是这样的。用户以更高的信任度启动 Silverlight OOB 应用程序。用户在应用程序中操作一些数据,但必须将部分数据提交到外部网站。如果我在 WebBrowser 控件中打开外部站点,是否可以通过对 DOM 的编程访问在外部站点的 Web 表单中预先填写一些信息来帮助用户?

Does anybody know if it is possible to access and manipulate an element in the html page that is rendered by the Silverlight 4 WebBrowser control.

The scenario is like this. The user launches a Silverlight OOB application with elevated trust. The user manipulates some data in the application but must submit part of the data to an external web site. If I open the external site in a WebBrowser control, is there any way I can assist the user by pre filling some information in the external sites' web form via programmatic access to the DOM?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不念旧人 2024-09-05 18:14:13

快速回答:否。

长答案:
OOTB + WebBrowserControl 的最初目的是帮助客户烘焙富文本格式显示(电子邮件、RSS 等),同时提供对大型文档(报告等)的打印支持的能力。

与此控件相同的规则适用于 iframe(据我所知,没有任何计划对此进行更改)。

你刚才提到的场景让我有点紧张,因为我看到 Silverlight 团队中的一些人提出了安全问题 - 因为这可以用作通过 Silverlight 对网站等进行自动 DOS 攻击的一种方法,因为毫无戒心有效负载(即使信任度提高,用户也经常被骗去安装这样的东西 - 这是现实,抱歉)..

-
Scott Barnes / 前 Silverlight 产品经理。

Quick answer: No.

Long Answer:
The original intent for the OOTB + WebBrowserControl was to help customers bake in both Rich Text Format displays (Email, RSS etc) and at the same time provide the ability for printing support for large documents to occur (reports etc).

The same rules apply for iframe as you have with this Control (as far as I know there isn't any plans to change this).

The scenario you just mentioned made me a little nervous as I can see a few of the guys on the Silverlight team raising the issue around security - in that this can be used as a way to automate DOS attacks on websites etc via Silverlight as the unsuspecting payload (even with elevated trust users are often duped into installing things like this - its the reality sorry)..

-
Scott Barnes / Former Silverlight Product Manager.

淡淡離愁欲言轉身 2024-09-05 18:14:13

您可以使用 InvokeScript 方法在 WebBrowser 控件内执行 javascript 函数。请注意,您无法进行跨域调用。

示例:

Html 页面

<html ><head>
    <script type="text/javascript">
        function SetValues(val) {
            document.getElementById("q").value = val;
        }
    </script>
</head><body>
<input type="text" id="q" />
</body></html>

Xaml

 <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="268*" />
            <ColumnDefinition Width="132*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <WebBrowser Name="webBrowser1" Grid.Row="1" Grid.ColumnSpan="2" />
        <Button Content="Search" Name="button1" Click="button1_Click" 
                Grid.Column="1" />
        <TextBox Name="textBox1" />
    </Grid>

代码隐藏

public MainPage()
{
  InitializeComponent();
  webBrowser1.Navigate(new Uri("http://localhost:58976/HTMLPage1.htm"));        
}

private void button1_Click(object sender, RoutedEventArgs e)
{         
  webBrowser1.InvokeScript("SetValues",textBox1.Text);
}

You can execute javascript functions inside the WebBrowser control using the InvokeScript method. Note that you can't make cross-domain calls.

Example:

Html page

<html ><head>
    <script type="text/javascript">
        function SetValues(val) {
            document.getElementById("q").value = val;
        }
    </script>
</head><body>
<input type="text" id="q" />
</body></html>

Xaml

 <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="268*" />
            <ColumnDefinition Width="132*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <WebBrowser Name="webBrowser1" Grid.Row="1" Grid.ColumnSpan="2" />
        <Button Content="Search" Name="button1" Click="button1_Click" 
                Grid.Column="1" />
        <TextBox Name="textBox1" />
    </Grid>

code behind

public MainPage()
{
  InitializeComponent();
  webBrowser1.Navigate(new Uri("http://localhost:58976/HTMLPage1.htm"));        
}

private void button1_Click(object sender, RoutedEventArgs e)
{         
  webBrowser1.InvokeScript("SetValues",textBox1.Text);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文