|
I would like to be able to grab the images from a web page and put them in a windows.bitmap object. The two main ways I have been able to do this have limitations that don't let them work in my application.
The images are downsampled copies of originals stored in a database. I can use axWebBrowser control to download and show the web page and extract the image address using an mshtml document object but the javascript on the page deletes the downsampled image as soon as it is loaded.
a WebRequest object could be used to download the html and then parse the html to get the address of the image but it won't run the javascrip to delete the copy from the server.
I have thought about a combination of downloading the html to a stream using webrequest, extracting the image url and copying the image to disk, substituting the new image file name into the html stream (so I don't have to download it twice) and then loading the new html into the axWebBrowser to run the script and finally loading the image from disk into a bitmap object.
There has to be a way though to read the bitmap data from the HTMLDocument or similar object directly though. I know the browser keeps it in memory as a bitmap so how do I access it? I have been playing around with the IHTMLDocument2 interface but haven't been able to figure out a way.
There has to be something simple that I am missing here. Any help woud be appreciated.
|
|
|
|
|
This blog[^] presented a way to generate an image of a web page with the use of the IHTMLElementRender interface, and we can customize the sample code to grab the image element on the web form. Instead of using the body element:
IHTMLElement element = (IHTMLElement) document.body; you can get the img element in the document, then you can draw the contents of the image:
IHTMLImgElement element = (IHTMLImgElement) document.images.item("image1", "");
|
|
|
|
|
I'm using a vb6 application to access a web page (hosted by a totally different company) that is seen in the webbrowser control on my form. I can get the value of a combobox, but I'm trying to see how to get the actual text of the item that is displayed. For instance, the combobox may have "minnesota" showing, but the value is 23. I want to know how I can get "Minnesota". I figured I could probably use the elements collection of the combobox and loop through to see if one is selected, but that seems pretty crappy. Anyoneone know how I can get this displayed text instead of the numeric value associated with the selected item?
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Hi there,
I'm not sure if you can do the equivalent in VB 6.
HTMLDocument doc = (HTMLDocument)axWebBrowser1.Document;
HTMLSelectElementClass select = (HTMLSelectElementClass)doc.getElementById("DropDownList1");
IHTMLElementCollection options = (IHTMLElementCollection)select.children;
HTMLOptionElementClass option = (HTMLOptionElementClass)options.item(select.selectedIndex, "");
string text = option.text;
|
|
|
|
|
I've never done javascript before but I need to be able to detect which browser the user is running. I've searched the net and copied some code to do this. It's simple and I understand what it does but I can't get the .html page to display different text per browser. This is what I have in my html:
<br />
<script language="JavaScript" type="text/JavaScript"><br />
<!--<br />
if(BrowserDetect()!="Internet Explorer")<br />
{<br />
document.write('Other');<br />
}<br />
else<br />
{<br />
document.write('Internet Explorer');<br />
}<br />
</script><br />
and this is the code that I found on the internet:
<br />
function BrowserDetect() {<br />
var detect = navigator.userAgent.toLowerCase();<br />
var OS,browser,version,total,thestring;<br />
<br />
if (checkIt('konqueror'))<br />
{<br />
browser = "Konqueror";<br />
OS = "Linux";<br />
}<br />
else if (checkIt('safari')) browser = "Safari"<br />
else if (checkIt('omniweb')) browser = "OmniWeb"<br />
else if (checkIt('opera')) browser = "Opera"<br />
else if (checkIt('webtv')) browser = "WebTV";<br />
else if (checkIt('icab')) browser = "iCab"<br />
else if (checkIt('msie')) browser = "Internet Explorer"<br />
else if (!checkIt('compatible'))<br />
{<br />
browser = "Compatible"<br />
version = detect.charAt(8);<br />
}<br />
else browser = "An unknown browser";<br />
<br />
if (!version) version = detect.charAt(place + thestring.length);<br />
<br />
if (!OS)<br />
{<br />
if (checkIt('linux')) OS = "Linux";<br />
else if (checkIt('x11')) OS = "Unix";<br />
else if (checkIt('mac')) OS = "Mac"<br />
else if (checkIt('win')) OS = "Windows"<br />
else OS = "an unknown operating system";<br />
}<br />
<br />
document.rs_browser=browser;<br />
document.rs_OS=OS;<br />
document.rs_version=version;<br />
<br />
return browser;<br />
}<br />
<br />
function checkIt(string) {<br />
place = detect.indexOf(string) + 1;<br />
thestring = string;<br />
return place;<br />
}
When I view my page in either FireFox or IE it doesn't generate any errors but it also doesn't display any sort of text.
Please Help,
Rob Tomson
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Try moving the first two lines of the BrowserDetect function -
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
- (ie the variable declarations) outside of the function - they are global variables (at least 'detect' and 'thestring' are also used in the checkIt function, so...)
cheers
Phil
|
|
|
|
|
That worked. Thanks! I guess I should keep an eye on what scope the variables are in.
Thanks,
Rob Tomson
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Hi, I want to open a new browser window, let the user use that window for several minutes, and when they close, I'd like to change the page displayed in the original window.
According to numerous articles found Googling, this should work, but on my WinXP system, using Firefox and IE, I get nothing (when allowing pop-ups, if pop-ups are disabled, IE reports the window is closed, Firefox gives a JS error on checking the window handle). No JS errors, no notifications, nothing. Any pointers would be appreciated.
File 1 contains the code I'm using to open the window, to check for closure, and a form textarea that I update with the time (mostly so I know my timer is firing properly).
---- FILE 1 BEG ----
<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><br />
<html><br />
<head><br />
<title>Opener Page</title><br />
</head><br />
<body><br />
<h1>Opener</h1><br />
<form name="frmOutput"><br />
<textarea name="txtOutput" rows=5 cols=80></textarea><br />
</form><br />
<p><a href="javascript:stopChecking();">Stop Checking</A></p><br />
<script language="Javascript"><br />
log("Start", true);<br />
<br />
var remoteWin = window.open("Remote.html", "remote", 'toolbar=no, location=no, directories=no, status=yes, menubar=no, width=795, height=500, resizable=yes, scrollbars=yes, screenx=0, screeny=0, top=0, left=0');<br />
var timer = null;<br />
<br />
function checkClosed()<br />
{<br />
log("Checking...", false);<br />
timer = setTimeout("checkClosed()", 5000);
if (!remoteWin)<br />
{<br />
alert("Window no longer exists");<br />
stopChecking();<br />
}<br />
else if (remoteWin.Closed)<br />
{<br />
alert("Window Closed"); <br />
stopChecking();<br />
} <br />
}<br />
<br />
timer = setTimeout("checkClosed()", 5000);
<br />
<br />
function stopChecking()<br />
{<br />
log("Stop checking.", false);<br />
clearTimeout(timer);<br />
}<br />
<br />
<br />
function log(sText, bClearContents)<br />
{<br />
var d = new Date();<br />
var s = d.getFullYear() + "." + d.getMonth() + "." + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " " + sText + "\r\n";<br />
if (bClearContents)<br />
{<br />
document.frmOutput.txtOutput.value = s; <br />
}<br />
else<br />
{<br />
document.frmOutput.txtOutput.value = s + document.frmOutput.txtOutput.value;<br />
}<br />
}<br />
</script><br />
<br />
<br />
</body><br />
</html><br />
<br />
---- FILE 1 END ----
File 2 contains some filler text. I can not change the source of this window (when live).
---- FILE 2 BEG (remote.html) ----
<br />
<html><head><title>Remote</title></head><body><h1>Remote Window</h1><p>Closing me should alert the original window or allow the original window to know when I <a href="javascript:window.close();">close</a>.</p></body></html><br />
---- FILE 2 END (remote.html) ----
TIA.
Glenn
|
|
|
|
|
Dont know too much about FF, but very easy to get working for you in IE:
Main file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Opener Page</title>
</head>
<body>
<h1>Opener</h1>
<form name="frmOutput">
<textarea name="txtOutput" rows=5 cols=80></textarea>
</form>
<p><a href="javascriptstopChecking();">Stop Checking</A></p>
<script language="Javascript">
log("Start", true);
var remoteWin = window.open("Remote.html", "remote", 'toolbar=no, location=no, directories=no, status=yes, menubar=no, width=795, height=500, resizable=yes, scrollbars=yes, screenx=0, screeny=0, top=0, left=0');
function notifyClosed()
{
log("Window closed",false);
}
function log(sText, bClearContents)
{
var d = new Date();
var s = d.getFullYear() + "." + d.getMonth() + "." + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " " + sText + "\r\n";
if (bClearContents)
{
document.frmOutput.txtOutput.value = s;
}
else
{
document.frmOutput.txtOutput.value = s + document.frmOutput.txtOutput.value;
}
}
</script>
</body>
</html>
remote window
<html>
<head>
<title>Remote</title>
<script language="javascript">
function closeWithNotify()
{
window.opener.notifyClosed();
self.close();
}
</script>
</head>
<body>
<h1>Remote Window</h1>
<p>Closing me should alert the original window or allow the original window to know when I <a href="javascript:closeWithNotify();">close</a></p>
</body>
</html>
|
|
|
|
|
Thanks, but this requires modifying the remote page, which is not an option. I have no control over the pages being displayed in the remote window.
--G
|
|
|
|
|
Hi, this will work in IE...
It is not a public standard so I don´t know how it works with FF.
<br />
var gRemoteWin<br />
function openWindow() {<br />
gRemoteWin = window.open("Test2.aspx", "remote");<br />
timer = setTimeout("checkClosed()", 5000);<br />
}<br />
<br />
function checkClosed() {<br />
if (!gRemoteWin.closed) {<br />
alert('exists...' + gRemoteWin);<br />
timer = setTimeout("checkClosed()", 5000);<br />
}<br />
else {<br />
alert('does not exist ...');<br />
}<br />
}<br />
/M
|
|
|
|
|
It works fine with FireFox. My code would have worked also, if I used remoteWin.closed instead of remoteWin.Closed.
Thanks for pointing that out.
--G
|
|
|
|
|
Hi,
I have a web page which has some table rows having background color. When I'm printing the page its not printing. I'm using IE 5.5 as the web browser. When I checked the Internet Options, the checkbox for Print background images and colors are not checked and when I checked this option and printed the page, the background color is printing. I need help for how to set the value of Print background images and colors checkbox to checked when I'm printing. I'm using only Javascript as the scription language and no database is used. If any of you have some ideas please send immediate response.
|
|
|
|
|
In what conditions the dialog ask for user name, password and domain will be triggered, after open IE for browing?
|
|
|
|
|
Hi there,
When the anonymous access is disabled for the web application, and the authentication mode is set to Windows, here I assume i'm talking about an ASP.NET application. For more information, you can see IIS Authentication[^]
|
|
|
|
|
Thanks for your reply!;)
Here I am just remake the environment. Our customer's environment.
In our development environment we have the direct access to internet, So there's no problem getting data from internet. But when it comes to our customer's environment it just didn't works, because the the way they gain access to internet. They have domain , they have proxy server, kind of complex environment.
They need to type the user name, password and which domain they're in in order to gain access to internet, but I just don't know how to remake it in our own environment!
|
|
|
|
|
How does your application access the resources on the internet? Does it use the WebRequest to create HttpWebRequest ?
|
|
|
|
|
through the
CInternetSession
CHttPFile
|
|
|
|
|
I'm not familiar with the MFC stuff, but in this case you need to specify the proxy server before accessing the resources on the internet. You may look at the parameters in the object constructor, or you can post this question in the C++ forum.
|
|
|
|
|
Actually the implement is not urgent, What I need the most is to mimic the environment!That is when everything set up, once I open IE for browing, I'll get a dialog box asking for user name, password and which domain you're in!
|
|
|
|
|
|
|
There is a setting in the Http stuff you are using to tell it to use the existing IE settings when connecting. That would do the trick.
|
|
|
|
|
Hey minhpc_bk,
If the user is already logged on to the network and authenticated, is there some way to set it up so that Windows authentication doesn't pop up the login dialog?
Matt Gerrans
|
|
|
|
|
Hi Matt,
It all depends on the browser the user uses to browse the application and the windows authetication mode applied to the application. For example, the ASP.NET application is using the Integrated Windows Authentication (best suited for an intranet environment), if the client uses the IE browser, then the login dialog does not pop up as the IE will first use the current Windows logon information to send to the server. If the authetication fails, the browser then prompt the user for a user name and password. For non-Microsoft browsers like FireFox ..., you may need to check their documentation, but AFAIK the FireFox by default prompts the user with the login dialog box.
|
|
|
|
|