none
C#如何用webview和網頁裡面的Java script 收送資料? RRS feed

  • 問題

  • 如題...
    小弟悟性不好

    目前在寫一個登入網站的程式

    我負責後端C#的部分要去和前端網頁做連結

    需要用webview跟前端網頁裡面的Java script收送資料

    希望有比較明瞭的範例可以參考
    有推薦C#關於網路和JS的書或是網站嗎?
    最近會一直遇到這類的問題
    但是比較沒經驗,google的 資料都一知半解
    想快點學好
    只好上來拜託高手們了

    

    2019年1月20日 上午 09:43

所有回覆

  • 最原始的就是用 AJAX ,不過現在都用套件了,例如 jQuery ,你要直接用套件嗎?

    不精確的問法,就會得到隨便猜的答案;自己都不肯花時間好好描述問題,又何必期望網友會認真回答?

    2019年1月20日 上午 10:04
  • 您可以參考這篇文件, 前端和後端的範例都有:

    Simple Login Form in Web API

    2019年1月21日 上午 12:54
  • 我不知道套件的意思是?

    我的情況是公司目前有一個前端的Server,裡面有資料網頁和Java script,

    我這邊需要寫一個C# 的Client程式用WebView連到Server端的login網頁

    跟裡面Java Script溝通,比如給它我的Serial number帳號密碼等資訊

    我需要讀到它回傳login登入成功或失敗的訊息,這個登入網頁內容如下的html檔

    想請問有相關code,網站或是書可以參考?

    因為我對C#和Java Script都不太熟

    希望能有明確點的範例可以參考

    感謝大家的收看

    <!doctype html>
    <html data-n-head-ssr lang="en-US" data-n-head="lang">
      <head>
        <title data-n-head="true">UBIQCONN OTA Webs</title><meta data-n-head="true" charset="utf-8"/><meta data-n-head="true" name="viewport" content="width=device-width, initial-scale=1"/><meta data-n-head="true" data-hid="description" name="description" content="This is a web portal for Ubiqconn IOT devices platform. Features of user auth, packages managments."/><meta data-n-head="true" data-hid="og:locale" name="og:locale" property="og:locale" content="en_US"/><meta data-n-head="true" data-hid="og:locale:alternate-zh-tw" name="og:locale:alternate" property="og:locale:alternate" content="zh_tw"/><link data-n-head="true" rel="icon" type="image/x-icon" href="/favicon.ico"/><link data-n-head="true" rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons"/><link data-n-head="true" data-hid="alternate-hreflang-en-US" rel="alternate" href="/webview/ubiqconn?debug=1" hreflang="en-US"/><link data-n-head="true" data-hid="alternate-hreflang-zh-tw" rel="alternate" href="/zh/webview/ubiqconn?debug=1" hreflang="zh-tw"/><script data-n-head="true" src="//www.googletagmanager.com/gtm.js?id=GTM-THLXX55&amp;l=dataLayer" async="true"></script><link rel="preload" href="/_nuxt/25f91f6b04f2c2181696.js" as="script"><link rel="preload" href="/_nuxt/f4cb6010fa3b840c9192.js" as="script"><link rel="preload" href="/_nuxt/cdbe1947aa7c36367eed.css" as="style"><link rel="preload" href="/_nuxt/dd7d78191973c573d89a.js" as="script"><link rel="preload" href="/_nuxt/3c6ad3ee41706e9cd2a9.css" as="style"><link rel="preload" href="/_nuxt/376fb189eb48fd4afb4f.js" as="script"><link rel="preload" href="/_nuxt/effd69e7ee75981c9c96.css" as="style"><link rel="preload" href="/_nuxt/e699acf2b08b4f4eb11f.js" as="script"><link rel="stylesheet" href="/_nuxt/0863325b36fc8809a20b.css"><link rel="stylesheet" href="/_nuxt/0c690c5930e9d9dde15f.css"><link rel="stylesheet" href="/_nuxt/3090dce2a74b341e1195.css"><link rel="stylesheet" href="/_nuxt/39de5b6ddefc1685f374.css"><link rel="stylesheet" href="/_nuxt/3c6ad3ee41706e9cd2a9.css"><link rel="stylesheet" href="/_nuxt/434655c0dad5c017727d.css"><link rel="stylesheet" href="/_nuxt/63f1af36c0340d6ed1d3.css"><link rel="stylesheet" href="/_nuxt/689ec8943bac98654e53.css"><link rel="stylesheet" href="/_nuxt/69989accf8e29ca9e96e.css"><link rel="stylesheet" href="/_nuxt/715d78cbd1036f6e9492.css"><link rel="stylesheet" href="/_nuxt/7db6a8e2b30e06f35952.css"><link rel="stylesheet" href="/_nuxt/89efccd62b34c305fca0.css"><link rel="stylesheet" href="/_nuxt/95508c9673e5a2b76926.css"><link rel="stylesheet" href="/_nuxt/9c08d5065e89cb836bb0.css"><link rel="stylesheet" href="/_nuxt/b3e484b1e8e7c2aeb6de.css"><link rel="stylesheet" href="/_nuxt/b6ac1948a65d6a2f8964.css"><link rel="stylesheet" href="/_nuxt/cdbe1947aa7c36367eed.css"><link rel="stylesheet" href="/_nuxt/d2235794fcbc4c3d9a2b.css"><link rel="stylesheet" href="/_nuxt/dee3e2e42f90cb5e2bdd.css"><link rel="stylesheet" href="/_nuxt/e2dc4ca92513720f7593.css"><link rel="stylesheet" href="/_nuxt/e4a03ad6f133149dd656.css"><link rel="stylesheet" href="/_nuxt/effd69e7ee75981c9c96.css">
      </head>
      <body data-n-head="">
        <div data-server-rendered="true" id="__nuxt"><!----><div id="__layout"><div data-app="true" id="app" class="application theme--light" data-v-e88e52a6><div class="application--wrap"><main class="v-content" style="padding-top:56px;padding-right:0px;padding-bottom:32px;padding-left:0px;" data-v-e88e52a6><div class="v-content__wrap"><div class="container main" data-v-e88e52a6><div data-app="true" id="login" class="application theme--light" data-v-ec337c36 data-v-e88e52a6><div class="application--wrap"><main class="v-content" style="padding-top:56px;padding-right:0px;padding-bottom:32px;padding-left:0px;" data-v-ec337c36><div class="v-content__wrap"><div class="container fluid fill-height" data-v-ec337c36><div class="layout justify-center" data-v-ec337c36><div class="flex xs12" data-v-ec337c36><div class="elevation-1 pa-3 v-card theme--light" style="height:100%;width:100%;" data-v-ec337c36><div class="v-card__text" data-v-ec337c36><div class="layout column align-center" data-v-ec337c36><img src="/ubiqconn/logo.svg" width="150" height="150" data-v-ec337c36> <h1 class="flex display-1 font-weight-medium primary--text" data-v-ec337c36>Ubiqconn</h1> <div data-v-ec337c36><div data-v-ec337c36><pre data-v-ec337c36>                    ```ex: tbsWebView.loadUrl(&quot;javascript:setSerial('SN_NUM')&quot;);```
    
                        window.setSerial=this.setSerial
                        window.getLoginResult=this.getLoginResult
                        window.getMyService=this.getMyService
                        window.getCheckSN=this.getCheckSN
    
                        ```ex: tbsWebView.addJavascriptInterface(new JsJavaBridge(this, tbsWebView), &quot;$App&quot;);```
                        window.$App.sendLoginResult()
                        window.$App.sendMyService()
                        window.$App.sendCheckSN()
                        </pre></div> <code data-v-ec337c36>
                        You are using mobile: unknown
                        setSerial: 
                        getLoginResult: 
                      </code> <!----> <!----></div></div> <!----> <!----> <form novalidate="novalidate" class="v-form" data-v-ec337c36><div class="v-input v-text-field v-input--is-label-active v-input--is-dirty theme--light" data-v-ec337c36><div class="v-input__control"><div class="v-input__slot" style="height:undefined;"><div class="v-text-field__slot"><label aria-hidden="true" class="v-label v-label--active theme--light" style="left:0px;right:auto;;">Login Email</label><input aria-label="Login Email" name="email" type="text" value="test@ubiqconn.com"></div><div class="v-input__append-inner"><div class="v-input__icon v-input__icon--append"><i aria-hidden="true" class="v-icon material-icons theme--light">person</i></div></div></div><div class="v-text-field__details"><div class="v-messages theme--light"><div class="v-messages__wrapper"></div></div></div></div></div> <div class="v-input v-text-field theme--light" data-v-ec337c36><div class="v-input__control"><div class="v-input__slot" style="height:undefined;"><div class="v-text-field__slot"><label for="password" class="v-label theme--light" style="left:0px;right:auto;;">Password</label><input name="password" id="password" type="password" value=""></div><div class="v-input__append-inner"><div class="v-input__icon v-input__icon--append"><i aria-hidden="true" class="v-icon v-icon--link material-icons theme--light">visibility</i></div></div></div><div class="v-text-field__details"><div class="v-messages theme--light"><div class="v-messages__wrapper"></div></div></div></div></div></form></div> <div class="v-card__actions" data-v-ec337c36><div class="layout row wrap" data-v-ec337c36><div class="flex xs12" data-v-ec337c36><button disabled="disabled" type="button" class="v-btn v-btn--block v-btn--disabled theme--light secondary--text" data-v-ec337c36><div class="v-btn__content">Login</div></button></div> <div class="spacer" data-v-ec337c36></div> <div class="flex xs5" data-v-ec337c36><a href="/register" class="body-2 font-weight-medium" data-v-ec337c36>
                        Create Account
                      </a></div> <div class="flex xs12" data-v-ec337c36><a href="/forgetPassword" class="body-2 font-weight-medium" data-v-ec337c36>
                        Forgot password?
                      </a></div></div></div></div></div></div></div></div></main></div></div></div></div></main> <footer right="" class="v-footer v-footer--fixed theme--light" style="height:32px;" data-v-073bf822 data-v-e88e52a6><div class="flex text-xs-right xs12" data-v-073bf822><!----><a href="/zh/webview/ubiqconn?debug=1" class="lang" data-v-073bf822><button type="button" class="v-btn v-btn--flat v-btn--small theme--light" data-v-073bf822><div class="v-btn__content"><i aria-hidden="true" class="v-icon material-icons theme--light" style="font-size:16px;" data-v-073bf822>language</i> 中文
          </div></button></a> <span data-v-073bf822>© 2018</span></div></footer></div></div></div></div><script>window.__NUXT__=(function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C){return {layout:"blank",data:[{}],error:i,state:{sidebar:o,snackbar:{visible:h,text:d,color:d},mqtt:{clientId:"UBIQWeb-72145"},ip:"172.16.2.71",redirectFrom:d,i18n:{locale:"en",messages:{project:{name:j},menu:{Apps:"Apps",dashboard:z,packages:"Packages","packages-upload":g,"packages-androidList":"Android List","packages-windowsList":"Window List","packages-history":"History",devices:a,"devices-list":"S\\N list",overview:"Overview","manage-device":a,"manage-member":e,"manage-group":b,group:b,"group-member":e,"group-device":"Devices Control",admin:"Admin Manage","admin-users":"User","admin-groups":"Group","admin-devices":"device",Admin:"Admin",Management:"Management"},links:{home:"Home",about:k,english:"English version",chinese:"Chinese version"},home:{title:"Discover Ubiqconn IOT",introduction:"Ubiqconn is a subsidiary of FIC Group which have more than 12,000 employees and professional manufacturing facility for various global industries.",title1:"Remote Update",introduction1:"Provide devices update OTA services. Save time and cost of physcal operation",title2:z,introduction2:"Web control and realtime communication to deivces",title3:"Security",introduction3:"Hosting on one of biggest cloud services",moredetail:"For more information visit our site on ",card:{packages:"Published packages",publishedChart:"Packages chart",connectDevices:a,deviceModel:"Devices Model"}},login:{title:"Ubiqconn platform",password:l,loginBtn:m},register:{alreadyRegister:n,email:"Login Email",name:"Full name",header:"Welcome to Ubiqconn",regBtn:f,registerNow:"Create Account",password_confirmation:p,subheader:"Please register and start managing your devices",title:f},changePassword:{org_password:"Origin password",new_password:"New password",new_password_confirmation:"Repeat new password"},about:{title:k,introduction:"This page is made to give you more informations."},devices:{title:q,Brand:r,All:"All",Model:s,Android:"Android",Windows:"Windows",Platform:"Platform",importBtn:"IMPORT S\u002FN",addBtn:"ADD S\u002FN",addDevices:"add devices",deviceDetail:"Device Detail",Name:"Name",packageVersion:t,EditDevice:"Edit Device",groupTitle:"Device groups",removeFromAllGroup:"Remove From All Group",ownerTitle:"Device owners",addToGroupTitle:u,"Remove from group":"Remove From Group",setOwner:"Set Owner"},mqtt:{devices:{title:"Channel"}},packages:{upload:{title:"Packages upload",selectPackage:"Select a package ZIP to upload",error:{wrongFileFormat:"Doesn't look like a package file! Missing `info.json`",release_title:"Relase title is not completed",release_description:v,platform:v,package_version:"Package Version is not completed",model:"model is not completed",brand:"brand is not completed",upgrade_order:"Upgrade Order is not completed"}},Brand:r,Model:s,releaseTitle:"Release Title",packageDetail:"Package Detail",packageVersion:t,prePackageVersion:"Pre Package Version",fileSize:"File Size",publishedTime:"Published Time",packagesList:"Packages List"},dialog:{upload:{title:"Upload Confim"},profile:{title:w},group:{createTitle:"Create Group",closeTitle:"Close Group",addMemberTitle:w,editTitle:"Edit Group",leaveTitle:"Leave Group",areYouSureToLeave:"Are you sure to leave group"}},error:{upload:{failure:"Upload failed, please try again later.",is_duplicate:"This package_version is exist!",is_older:"This package_version is not newsest.",is_duplicate_older:"This package_version is exist and not newsest."},connection:"Server Error"},common:{cancel:"Cancel",upload:g,done:"DONE",pickFile:"Choose file",logout:"Logout",login:m,create:x,add:"Add",Item:"ITEM",Status:"STATUS",Action:"Action",rowPerPage:"Row per page",search:"search",searchType:"Search type",createdTime:"Created Time",Detail:"Detail",Publish:"Publish",version:"version",remove:"remove",noData:"Please enter another keyword, or ",noDataRefreshBtn:"click me to refresh",Delete:"Delete",View:"View",Edit:"Edit",Online:"Online",Offline:"Offline",Devices:a,Members:e,rename:"Rename",groups:b,owners:"Owners",Leave:"Leave",addSN:"Add S\u002FN",close:"Close",save:"Save",send:"Send",update:"Update",set:"set"},snackbar:{changedPassword:"Password has been changed",addedDevice:"Device has been added",editedDevice:"Device has been edited",addedGroup:"Group %s has been created",editedGroup:"Group %s has been saved",leaveGroup:"You have been removed from the group",sharedGroupDevice:"Your devices have been shared",sentEmail:"Email have been sent"},validate:{required:"Required",email:{required:"Please enter an E-mail ",valid:"Doesn't look like a valid E-mail"},password:{match:"Password does not match"}},importValidate:{required:"field is required",distinct:"Upload unique validation failed on serial_number",unique:"has already been taken",in:"invalid"},profile:{changePassword:y,Profile:"Profile",Activity:"Activity",Email:c},my:{userTitle:"My Users",groupTitle:"My Groups",deviceTitle:"My Devices"},admin:{usersTitle:A,groupsTitle:"Groups List",devicesTitle:q},users:{usersList:A,createBtn:x,creatUser:"Creat User",editUser:"Edit User",Email:c,changePassword:y,groupTitle:b,deviceTitle:a,addToGroupTitle:u,blockUser:"Block user",activateUser:"Activate user"},member:{groupTitle:"Member's groups"},group:{form:{userNotExists:"User not exists"},shareDevices:"Share devices to groups",deviceTitle:"Group Devices",removeFromAll:"Remove from all groups",removeMemberFromGroup:"Remove user","removeMemberFromAllConfirm%s":"Are you sure remove %s from all group?","removeDeviceFromAllConfirm%s":"Are you sure remove %s from all my groups?","removeMemberFromGroupConfirm%s":"Are you sure remove %s from group %s?","userAlreadyExist%s":"User %s already in group","userAddedToGroup%s":"User %s has been added to %s"},forgetPassword:{forgetPasswordBtn:"Forgot password?",email:c,sendEmail:"Send Email",title:"Fill your register email.",alreadyPassword:n},resetPassword:{backToLogin:B,resetPasswordBtn:"Reset",title:"Reset Password",new_password:l,new_password_confirmation:p},reSendValidationEmail:{reSendValidationEmailBtn:C,title:C,email:c,backToLogin:B,reSendEmail:"Resend Email"},webview:{ruggon:{title:"Ruggon Insight"},ubiqconn:{title:j}}}},auth:{user:i,loggedIn:h,strategy:"local"}},serverRendered:o}}("Devices","Groups","Email","","Members","Register","Upload",false,null,"Ubiqconn","About","Password","Login","I am already a member",true,"Repeat password","Devices List","Brand","Model","Package Version","Add To Group","Release description is not completed","Add new member","Create","Change Password","Dashboard","Users List","Back to login","Resend verification email"));</script><script src="/_nuxt/25f91f6b04f2c2181696.js" defer></script><script src="/_nuxt/e699acf2b08b4f4eb11f.js" defer></script><script src="/_nuxt/f4cb6010fa3b840c9192.js" defer></script><script src="/_nuxt/dd7d78191973c573d89a.js" defer></script><script src="/_nuxt/376fb189eb48fd4afb4f.js" defer></script>
      </body>
    </html>

    2019年1月21日 上午 06:08
  • https://docs.microsoft.com/en-us/dotnet/api/microsoft.toolkit.forms.ui.controls.webview.invokescript?view=win-comm-toolkit-dotnet-stable#Microsoft_Toolkit_Forms_UI_Controls_WebView_InvokeScript_System_String_

    InvokeScript 或是非同步的 InvokeScriptAsync

    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。 https://skilltree.my/

    2019年1月21日 上午 11:45
    版主