Notifications
Clear all

[Closed] webrowser url

Using dotnet webrowser with following page ‘ http://suncalc.net/#/39.9871,-86.1349,12/2013.04.24/22:06 ’. Am trying to get string from url whenever page is updated (whenever point is drag-droped on page or date is changed). Any ideas?

5 Replies

Hello, what is your non-working code, exactly?
At least a simple sample of your wrong code so that somebody can help you.

Here’s a sample. Commented out stuff I’ve tried. Not sure if ‘on axWeb_GPS Navigated txt do ’ is best method or not either. Basically whenever suncalc.net links are tried in browser (firefox) it updates url when data is entered or location is moved. Trying to get same thing here with what updated url is.



		
rollout ro1lout_GPS "GPS Location" --width:900 height:600
(

	edittext axWeb_link "" width:850 align:#left
	
		button axWeb_back "BACK" width:60 height:20 align:#left offset:[10,10]
		button axWeb_forward "FORWARD" width:60 height:20 align:#left offset:[10,-5]
		
		button GPS_link1 "suncalc.net" width:100 height:20 align:#left offset:[90,-45]
		button GPS_link2 "weather.com" width:100 height:20 align:#left offset:[90,-5]
		
		
	groupBox GPS_grp_Apply "Apply " width:120 height:80 pos:[220,30] --offset:[0,-0]
	
		button GPS_ApplyLocation "Apply Location" width:100 height:20 align:#left offset:[220,-70] tooltip:"Data applyed to location"
		button GPS_ApplyStart "Apply Start" width:100 height:20 align:#left offset:[220,-5] tooltip:"Data applyed to date/time start"
		button GPS_ApplyStop "Apply Stop" width:100 height:20 align:#left offset:[220,-5] tooltip:"Data applyed to date/time stop"
		
	groupBox GPS_grp_Suncalc "Suncalc Data" width:120 height:80 pos:[350,30] --offset:[0,-0]

		
		button GPS_suncalcDataIn "<<" width:50 height:20 align:#left offset:[370,-60] tooltip:"Data to suncalc.net"
		button GPS_suncalcDataOut ">>" width:50 height:20 align:#left offset:[370,-5] tooltip:"Data from suncalc.net"
		
	
	groupBox GPS_grp_Data "Data" width:380 height:120 pos:[480,30] --offset:[0,-0]
	
			label GPS_lbl_Mocon_MonthDayYear "Month : Day : Year" align:#left offset:[500,-110]
			Spinner GPS_Mocon_Month fieldWidth:25 range:[1, 12, 4] align:#left type:#integer enabled:true offset:[510,0]
			Spinner GPS_Mocon_Day fieldWidth:25 range:[1, 31, 1] align:#left type:#integer enabled:true offset:[550,-20]
			Spinner GPS_Mocon_Year fieldWidth:40 range:[0, 20000, 2013] align:#left type:#integer enabled:true offset:[590,-20]


			label GPS_lbl_Mocon_HourMinuteSecond "Hour : Minute : Second" align:#left offset:[500,0]
			Spinner GPS_Mocon_Hour fieldWidth:25 range:[1, 24, 21] align:#left type:#integer enabled:true offset:[510,0]
			Spinner GPS_Mocon_Minute fieldWidth:25 range:[0, 59, 30] align:#left type:#integer enabled:true offset:[550,-20]
			Spinner GPS_Mocon_Second fieldWidth:25 range:[0, 59, 0] align:#left type:#integer enabled:true offset:[590,-20]


	
			label  GPS_lbl_Mocon_GPSLatitude "GPS Latitude:"  align:#left offset:[680,-70] 
			Spinner GPS_Mocon_GPSLatitude fieldWidth:50 range:[-90, 90, 39.9784] align:#left type:#float enabled:true offset:[760,-20]
			
			label  GPS_lbl_Mocon_GPSLongitude "GPS Longitude:"  align:#left offset:[680,5] 
			Spinner GPS_Mocon_GPSLongitude fieldWidth:50 range:[-180, 180, 86.118] align:#left type:#float enabled:true offset:[760,-20]
		
				
		dotNetControl axWeb_GPS "System.Windows.forms.WebBrowser" width:850 height:500 pos:[10,160] --AddressBar:true setupEvents:true
		
	
--------------------------------------------------------	
	
			on ro1lout_GPS open do
			( 
				enableAccelerators = false
				
				ro1lout_GPS.axWeb_GPS.IsAccessible = true
								
				global urlForm = "http://suncalc.net/#/39.9784,-86.118,12/2013.04.02/02:17"
				
				axWeb_link.text = urlForm as string
				axWeb_GPS.Navigate (urlForm as string)
				
				
			)
			

--------------------------------------------------------			
			

			on axWeb_link entered txt do axWeb_GPS.Navigate (txt as string)
			on axWeb_back pressed do axWeb_GPS.GoBack()
			on axWeb_forward pressed do axWeb_GPS.GoForward()

--------------------------------------------------------
--------------------------------------------------------

			on axWeb_GPS Navigated txt do 
			(
			
				--ro1lout_GPS.axWeb_GPS.Refresh()
				--ro1lout_GPS.axWeb_GPS.Update()
									
				--ro1lout_GPS.axWeb_GPS.url.AbsoluteUri
			
				global urlString = ro1lout_GPS.axWeb_GPS.Url.ToString()
				
				ro1lout_GPS.axWeb_link.text = urlString --as string
				
				
				enableAccelerators = false

			)
	
--------------------------------------------------------

			on ro1lout_GPS close do
			(

				enableAccelerators = true
			
			)

--------------------------------------------------------


	)











Any ideas on this? Think would involve getting data from javascript here: http://suncalc.net/scripts/main.js which involves ‘updateAddressHash’. Not sure how to go about getting this.

I think you can use informations from this link:

http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control

on axWeb_GPS Navigated txt do 
(
    local dnHtmlDoc = ro1lout_GPS.axWeb_GPS.Document;
    local dnHead = (dnHtmlDoc.GetElementsByTagName "head").Item 0;
    local dnScriptElt = dnHtmlDoc.CreateElement "script";

    ..stuck here to cast dnScriptElt into IHTMLScriptElement
    local dnHtmlScriptElement;
    dnHtmlScriptElement.text = "function getAddresshash() { alert('getAddresshash') }";

    dnHead.AppendChild(dnScriptElt);
    dnHtmlDoc.InvokeScript("sayHello");
)

Unfortunately, I cannot get it working because I do not know how to cast script element into IHTMLScriptElement.

But if someone can get it working, just replace the function text based on “updateAddressHash” function to get the address and set it yourself.

1 Reply
(@feranti)
Joined: 11 months ago

Posts: 0

Reading me again, it seems a messy explanation…

Your goal is to update the address bar of the Webbrowser when clicking on the map, as do the online original website.

You can get this newly generated address by writing a javascript function, let’s say GetUpdatedAddress() (reusing the code of updateAddressHash() and returning a string).

The problem is to insert the new function in the html code of the page. The link I submit is discussing of that.
Once you get the string of the address as it should be (and as it is in the website), you can modify the address bar string yourself with the value returned by GetUpdatedAddress().

As I said, I didn’t managed to get it working because it is using some specific c# stuff that I don’t know how to convert in maxscript.
One way would be to compile a derived class of the dotnet browser on-the-fly including a pre-build method InjectScriptCode() method doing the javascript injection by itself.
Then, inject your function GetUpdatedAddress() and call it with InvoKeScript().

I hope I was clear enough this time.
Hope it helps