473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

webBrowser control embedded in page doesn't get body element

7
Hi,
I'm trying to get the body element of a page using a webBrowser control. Right now I'm testing in javascript to make sure i can access the body through the webBrowser control, but soon I'll create an activeX control and use the control from there.
My code is:

var wb = document.getElementById("wbSave");
wb.Navigate(window.location);
var body= wb.Document.body;

The point is I don't know why the body is always null. If I analize the Document children I see it contains the "head" element and its contents but I would expect it to contain the body as another child too, and however it doesn't. I've searched online in several forums and everybody seems to access the body element this way, I just can't. I'm completely clueless.
So, please if anyone can give me any help on this, it will be appreciated.

Thanks in advance

Kenia
Mar 20 '08 #1
5 3290
acoder
16,027 Expert Mod 8TB
Is this a .NET control?
Mar 22 '08 #2
kenia
7
Hi and thanks for replying.
No, it's not a .Net control, it's the ActiveX control used by InternetExplorer.
Below is the code of my page

[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id = "head">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Salvar reporte</title>
<script>
function window_onload()
{
if(window.opener != null)
{
var content = window.opener.document.getElementById("messages");
var pageBody = document.getElementById("pageBody") ;
var div = document.createElement("div");
div.innerHTML = content.innerHTML;

//Add styles
var openerStyle = window.opener.document.getElementById("style");
var style = document.createElement("style");
style.setAttribute("type", "text/css");

//IE compatible
if(style.styleSheet)
{
style.styleSheet.cssText = openerStyle.styleSheet.cssText;
} else // w3c (Firefox)
{
var text = openerStyle.childNodes[0].nodeValue;
style.appendChild(document.createTextNode(text));
}

var head = document.getElementById("head");
head.appendChild(style);

pageBody.appendChild(div);
}
}

function save()
{
var wb = document.getElementById("wbSave");
wb.Navigate(window.location);
var doc = wb.Document;
alert(doc.body);
//wb.ExecWB(4,1);
}
</script>
</head>

<body onload="window_onload()" id="pageBody">
<object id="wbSave" width=0 height=0 classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<p id="par">this is a test</p>
<input type="button" onclick="save()" value="Save" />
</body>
</html>
[/HTML]
I'm always getting a null value, and I read on MSDN and it should work, so I'm completely clueless, don't know what else to try....
If you have any idea, please share it with me.

Thanks a lot

Kenia
Mar 24 '08 #3
pronerd
392 Expert 256MB
Hi and thanks for replying.
No, it's not a .Net control, it's the ActiveX control used by InternetExplorer.
Below is the code of my page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id = "head">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Salvar reporte</title>
<script>
function window_onload()
{
if(window.opener != null)
{
var content = window.opener.document.getElementById("messages");
var pageBody = document.getElementById("pageBody") ;
var div = document.createElement("div");
div.innerHTML = content.innerHTML;

//Add styles
var openerStyle = window.opener.document.getElementById("style");
var style = document.createElement("style");
style.setAttribute("type", "text/css");

//IE compatible
if(style.styleSheet)
{
style.styleSheet.cssText = openerStyle.styleSheet.cssText;
} else // w3c (Firefox)
{
var text = openerStyle.childNodes[0].nodeValue;
style.appendChild(document.createTextNode(text));
}

var head = document.getElementById("head");
head.appendChild(style);

pageBody.appendChild(div);
}
}

function save()
{
var wb = document.getElementById("wbSave");
wb.Navigate(window.location);
var doc = wb.Document;
alert(doc.body);
//wb.ExecWB(4,1);
}
</script>
</head>

<body onload="window_onload()" id="pageBody">
<object id="wbSave" width=0 height=0 classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<p id="par">this is a test</p>
<input type="button" onclick="save()" value="Save" />
</body>
</html>

I'm always getting a null value, and I read on MSDN and it should work, so I'm completely clueless, don't know what else to try....
If you have any idea, please share it with me.

Thanks a lot

Kenia
One potential issue I see is that you are calling the JS function before the body tag is fully loaded. You might try moving the function call to the end of the page after the closing body tag. I do not know about ActiveX, but I know in JS you will usually have problems if you run a function on an element that has not yet been loaded in the page.
Mar 24 '08 #4
kenia
7
One potential issue I see is that you are calling the JS function before the body tag is fully loaded. You might try moving the function call to the end of the page after the closing body tag. I do not know about ActiveX, but I know in JS you will usually have problems if you run a function on an element that has not yet been loaded in the page.
The function that's called when the body onload event fires is not the one that has the problem. Actually the save() function is the one that uses the ActiveX, and it's called when the save button is pushed, by that time the body is completely loaded.
If you see something else... please let me know.

Thanks

Kenia
Mar 24 '08 #5
acoder
16,027 Expert Mod 8TB
I'm always getting a null value, and I read on MSDN and it should work,
Can you provide the link for that? If there's an example, have you tried the example only?
Mar 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: BKM | last post by:
I've been using the following 2 ways to make sure my WebBrowser is finished loading a page before continuing with the next code. do:doevents:loop while WebBrowser.Busy do:doevents:loop until...
7
by: Noozer | last post by:
I am able to place values on forms that load into my webbrowser control, but I'd like to be able to scan the page for data. I know to use the HTMLDocument object. Basically I'm hoping to find an...
1
by: Vetrivel | last post by:
Application architecture : Develop interface between two existing systems, a. Enterprise CRM system b. Web based intranet system. Environment : Intranet Server : IIS and ASP. Script :...
8
by: Prosperz | last post by:
Hi, I would like to make thumbnails of web page by capture content of a WebBrowser. By example, capture http://www.google.com. I used WebBrowser control with Framework 2.0. I try this : ...
1
by: L. Chernov | last post by:
Hello, I am trying to work with .Net 2005 WebBrowser object, and put it on a "Windows control library" (embedded in a user control class) and then I am executing it from an ASP.Net webform(with...
0
by: Jocker | last post by:
Hi, I'm trying to get an image of the whole page displayed in the WebBrowser control (.net 2.0) OleDraw function should be the way to go.. I've put up the following code, but it captures only a...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
8
by: Ludwig Wittgenstein | last post by:
Hi, all. How can i hook up an InternetExplorer object to a WebBrowser control that I have in my windows form. Basically what I want to do is automate the WebBrowser control via the...
6
by: titan.nyquist | last post by:
The WebBrowser control won't load a css file written in the same directory as the program. If I put an absolute path to it, it will load it. Thus, the current directory of the WebBrowser control...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.