寻找一个特定的标签 [英] Looking for a specific tag

查看:279
本文介绍了寻找一个特定的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个上一个问题关于在使用Chrome时从网页中访问代理卡的方法。我现在正试图用嵌入式CefSharp对象使用vb.Net应用程序。我有代码需要访问代理卡(感谢智能卡API ),但我需要这是一个简单的方法来表明这是一个选择。我的想法是:

I had a previous question regarding a way to access a proxy card from within a web page when using Chrome. I'm now attempting to instead use a vb.Net application with an embedded CefSharp object. I have the code I need to access the proxy card (thanks to Smart Card API), but I need an easy way to indicate that this is even an option. My thought is to:


  1. 将另一个空的元素放在网页上(如< div id = 'smartcard'/>

  2. 在Visual Basic内部,监视此页面的内容< div /> / code>

  1. Put an otherwise empty element on the web page (such as <div id='smartcard' />)
  2. Inside Visual Basic, monitor the contents of the page for this <div />

  1. 如果找到< div /> ,请确保检测到读卡器。如果是这样,请在其内容中添加一些文字(可能是图片),表示可以扫描卡片。

  2. 一旦检测到卡扫描,将卡中的值放入表单元素并且POST它

  1. If the <div /> is found, make sure the card reader is detected. If so, add some text (and maybe an image) to its contents indicating the the card can be scanned
  2. Once a card scan is detected, put the value from the card into a form element and POST it


我似乎有可能会要使用JavaScript和vb.net代码的一些组合,但是我对CefSharp很新,我真的不知道从哪里开始。

It seems likely to me that I'm going to have to use some combination of JavaScript and vb.net code, but I'm so new to CefSharp that I really have no idea where to start.

提前感谢所有您的帮助。

Thanks in advance for all your help.

推荐答案

不是C#程序员,我查看了一般用法指导了很多次,仍然没有真正理解它。也就是说,我想我已经能够把这个项目搞定了。除了CefSharp项目之外,我还使用CardWerk的非免费智能卡API

Not being a C# programmer, I looked at the information on the General Usage guide many times and still didn't really understand it. That said, I think I've been able to get this project off the ground. In addition to the CefSharp project, I'm also using the non-free Smart Card API from CardWerk.

以下是我所做的一些片段。

Below is some snippets of what I did.

Imports CefSharp
Imports Subsembly  ' For the SmartCard namespace

Class MainWindow
    Private WithEvents CardManager As SmartCard.CardTerminalManager

    Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized

        browser.Address = "https://jake-dev7.local/trainingmatrix/"

        Debug.Print(SmartCard.SMARTCARDAPI.API_VERSION)
        CardManager = SmartCard.CardTerminalManager.Singleton
        CardManager.Startup(True)
    End Sub

    Private Sub browser_LoadingStateChanged(sender As Object, e As LoadingStateChangedEventArgs) Handles browser.LoadingStateChanged
        Dim script As String

        If Not e.IsLoading Then
            If CardManager.SlotCount Then
                script = "if ($('#proxcard').length) { proxcard_init() }"
                browser.GetMainFrame().ExecuteJavaScriptAsync(script)
            End If
        End If
    End Sub

    Protected Sub InsertedEvent(ByVal aSender As Object, ByVal aEventArgs As SmartCard.CardTerminalEventArgs) Handles CardManager.CardInsertedEvent
        Dim aCard As SmartCard.CardHandle
        Dim nActivationResult As SmartCard.CardActivationResult
        Dim iFacilityCode As Integer
        Dim iCardID As Integer

        ' There's a bunch of code here taken from the sample code that came 
        ' with the SmartCard API from CardWerk to pull the facility code and
        ' card id out of the prox card.

        If iFacilityCode <> 0 And iCardID <> 0 Then
            Dim script As String

            script = "if ($('#proxcard').length) { proxcard_scan(" & iFacilityCode & ", " & iCardID & ") }"
            browser.GetMainFrame().ExecuteJavaScriptAsync(script)

        End If
    End Sub
End Class



JavaScript



(这是一个 .js 文件由网页加载,此页面也可以加载到Chrome,Firefox,IE等,这些功能将永远不会运行,这个功能可以保持这个实用程序可用于没有自定义 .exe 和读卡器)。

// These proxcard_* functions are called via our parent application
// (CefSharp object embeded in a vb.Net assembly)
function proxcard_init() {
    $('#proxcard').html("<div class='or'>- OR -</div><div><img src='proxcard.jpg'><br>Scan your card</div>");
}

function proxcard_scan(facilityID, cardID) {
    var vars = {
       facilityID: facilityID,
       cardID: cardID
    };
    if ($('form#adduser').length) {
        // We're on the add user page. Check to see if this card matches somebody.
        $.post('httprequest.php?type=get-emp-from-prox', vars, function(data) {
            if (data && data.number) {
                // Update UI and backend form fields. If everything validates, submit the form
            } else {
                // Clear UI and backend form fields that pertain to user ID
                alert('Card not found');
            }
        }, 'json');
    } else if ($('form#update').length) {
        // Deal with the update form
    }
}

在我的实际代码中,我有多个 else if 语句来处理不同的表单,我允许扫描一张卡片。它们不包括在内以避免失控:)。

In my actual code, I have multiple else if statements for dealing with different forms where I allow a card to be scanned. They are not included to keep this from getting out of hand :).

请注意:这不是整个项目或使用CefSharp处理prox卡所需的所有代码。我希望足够帮助别人。

Please Note: This is not intended to be the entire project or all the code needed to process prox cards using CefSharp. My hope is that it will be enough to help somebody else.

这篇关于寻找一个特定的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆