Author Topic: How can I get the var of Java Script via c# webBrowser?  (Read 928 times)

0 Members and 1 Guest are viewing this topic.

Offline liuwei0622

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -5
    • View Profile
How can I get the var of Java Script via c# webBrowser?
« on: November 05, 2013, 03:50:02 pm »
Hi guys, I met this problem, any help is appreciate. thanks.

How can I get the var of Java Script from c# webBrowser? 
Below is part code of the html, the function in JS does not have name.

<script type="text/javascript">
dojo.require("myrta_tbs_dojo.portlethelper.chooseTime");
var portletHelper_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_;
var containsPreferredDate = false;
var containsSelectedDate = true;
var weekDate = new Date('Mon Nov 25 00:00:00 EST 2013');
var timeslots = { "ajaxresult" : { "slots" : {
  "nextAvailableDate" : "27/11/2013 14:50",
  "listTimeSlot" : [ {
    "startTime" : "25/11/2013 8:35",
    "availability" : false,
    "slotNumber" : null 
  }, {
    "startTime" : "01/12/2013 15:35",
    "availability" : false,
    "slotNumber" : null
  } ]
}}};
var stSelectedSlot = '2013/11/28 08:35';
var timetableInterval = [515, 890, 935];
var extendedRangeFlag = false;
 
dojo.addOnLoad( function() {
  portletHelper_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_ =
      new myrta_tbs_dojo.portlethelper.chooseTime({portlet: portlet_ns_Z7_0HEPVU271835D0IFC7B1OP10Q2_});
 
    dojo.require("myrta_tbs_dojo.portlethelper.chooseLocation");

how can I get the value of timeslots in c# code via WebBrowser? thanks.
« Last Edit: November 06, 2013, 03:32:38 am by liuwei0622 »

Offline liuwei0622

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -5
    • View Profile
Re: How can I get the var of Java Script via c# webBrowser?
« Reply #1 on: November 06, 2013, 01:08:43 pm »
I am not very understand, could you pls give me more information? Thanks

Offline liuwei0622

  • /dev/null
  • *
  • Posts: 7
  • Cookies: -5
    • View Profile
Re: How can I get the var of Java Script via c# webBrowser?
« Reply #2 on: November 06, 2013, 03:39:04 pm »
thanks for your response. I can get the variable using below code (using mshtml)

IHTMLDocument2 vDocument = this.webBrowser1.Document.DomDocument as IHTMLDocument2; IHTMLWindow2 vWindow = (IHTMLWindow2)vDocument.parentWindow;
Type vWindowType = vWindow.GetType();
object testText = vWindowType.InvokeMember("timeslots",
                    BindingFlags.GetProperty, null, vWindow, new object[] { });

but how can I parse the testText to get the value? the type is MarshalByRefObject.
does anyone know it? Thanks.