Custom HTML script for web browser not working s expected

Purgitoria

New member
Joined
Jun 15, 2019
Messages
1
Programming Experience
Beginner
I am currently trying to integrate a weather widget into my software from a freely available source and i can get my form to load if i write the code as follows (method 1):

C#:
WebBrowser1.DocumentText = "<html><img src=http://www.7timer.info/bin/astro.php?lon=-2.36&lat=55.91&lang=en&ac=0&unit=metric&tzshift=0 </html>";


What i want to do however is be able to dynamically alter the html code by using global variables defined in the parent form to insert the corrected lattitude and longitude into the code. The idea being that the user can enter their Lat/Lon on the parent form where it is used for other purposes but those values will then be the base for generating a corrected local weather forecast. The code i have to do this is (method 2):

C#:
string myweather = "<html><img scr=http://www.7timer.info/bin/astro.php?lon=" + Global_Variables.Longitude + "&lat=" + Global_Variables.Lattitude + "&lang=en&ac=0&unit=metric&tzshift=0 </html>";
WebBrowser1.DocumentText = myweather;

Method 1 works just fine and the form populates with the weather forecast but when i use method 2 the form is always blank. I have used the debugger and written out the value generated by metho2 and it returns exactly the same as what was defined in method 1. I have tried various iterations such as

C#:
WebBrowser1.DocumentText = (char)34+myweatheer+(char)34

and also having it as a variable instead of a string but nothing i seem to do makes any difference and the (char)34 method only drops quotation marks into the form with a gap inbetween and the rest of the form is blank. I really cant understand how a different method that returns exactly the same value does not seem to work?

There is literally no more code within the form itself as it's only purpose is to be a pop up child form that displays a graphical weather forecast. When a button is clicked on the parent form then this one opens up and contains only a web browser container with this html code inserted into the container. If i go to the website referenced in the code there are option for setting parameters and generating the html string that can be copied and pasted into your own website if you wish. Alternately you can write your own string in the correct format to make the same query and return an image with the weather forecast. In fact if i take the resulting output of "myweather" without the "" and paste it into a web browser i do actually get the web browser showing exactly the image i am expecting. Am i missing something fundamental in the way i am trying to do this?
 
HTML attribute values have to be inside quotes. Double-quotes are preferable but single-quotes are supported too. Also, you might want to consider closing your img tag.
 
Notice that the difference here:
C#:
src=http://www.7timer.info/bin/astro.php
scr=http://www.7timer.info/bin/astro.php

"src" in the working case vs. "scr" in the non-working case.
 
HTML attribute values have to be inside quotes. Double-quotes are preferable but single-quotes are supported too.
Yes!

The HTML 5 (RFC 7992) Section 4 says:
Double quotes (U+0022 QUOTATION MARK: ") are used to quote attribute values unless the HTML specification forbids quoting a particular attribute.
but the older HTML 2 (RFC 1866) Section 3.2.4 says:
A string literal, delimited by single quotes or double quotes and not containing any occurrences of the delimiting character.

Also, you might want to consider closing your img tag.
Unfortunately RFC 7992 Section 9.5.3 says otherwise:
Note: the HTML <img> element does not have a closing slash.
 
Assuming you are referring to </img> Jmc? :: RFC 7992 - HTML Format for RFCs

This might be worth a note ::
Other artwork will have a "src" attribute that uses the "data" URI
scheme defined in [RFC2397]. Such artwork is rendered in an HTML
<img> element. Note: the HTML <img> element does not have a closing
slash.

Note: such images are not yet allowed in RFCs even though the format
supports them. A limited set of "data:" mediatypes for artwork may
be allowed in the future.

<div class="artwork art-logo" id="s-2-58">
<img alt="IETF logo"
src="data:image/gif;charset=utf-8;base64,...">
<a class="pilcrow" href="#s-2-58">&para;</a>
</div>

Or are you just nit picking at the missing />? Skydiver's post is still correct under the assumption of your post re- an image tag. It's a closing bracket that missing, not an image tag.

With <html><img src=http://www.7timer.info/bin/astro.php?lon=-2.36&lat=55.91&lang=en&ac=0&unit=metric&tzshift=0 </html> - This markup syntax is wrong without a closing />.
 
Last edited:
Or are you just nit picking at the missing />? Skydiver's post is still correct under the assumption of your post re- an image tag. It's a closing bracket that missing, not an image tag.

With <html><img src=http://www.7timer.info/bin/astro.php?lon=-2.36&lat=55.91&lang=en&ac=0&unit=metric&tzshift=0 </html> - This markup syntax is wrong without a closing />.
Yeah, it was the closing > that was missing that I was referring to. Probably poor wording on my part, given the ambiguity of the term "closing" in that context.
 
Back
Top Bottom