473,394 Members | 2,100 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,394 software developers and data experts.

mshtml - access denied for Writeln()

sam

Hi

Just encountered a strange problem and wonder if it is a
bug ? I have the following piece of code....

try
{
IHTMLDocument2 MyDoc = (IHTMLDocument2
MyWebBrowser.Document;
IHTMLWindow2 MyWin = (IHTMLWindow2 ) MyDoc.open
("","_TEST_","","");

MyWin.document.writeln("line #1");
MyWin.document.writeln("line #2");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}

This opens the new WebBrowser, and writes the "line #1"
into it. But while writing the second line it throws an
exception "access denied"
Seems like I am allowed to access the "document" property
of the "IHTMLWindow2" only once.
If I try to access it again, I get this exception.

I found a work around.....
Basically I extract the MyWin.document into a variable of
IHTMLDocument2 and then invoke the writeln().
try
{
IHTMLDocument2 MyDoc = (IHTMLDocument2)
IWeb2.Document;
IHTMLWindow2 MyWin = (IHTMLWindow2 ) MyDoc.open
("","_TEST_","","");
IHTMLDocument2 MyDoc2 = (IHTMLDocument2)
MyWin.document;

MyDoc2.writeln("line #1");
MyDoc2.writeln("line #2");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
This works, but it is not foolproof. if I try to access
MyWin.document again at some other time... eg when I
invoke the function again, I still get the exception.

Anybody any clues?

TIA
sam
Nov 15 '05 #1
3 3882
im not sure without opening and testing it but its possible its because your
not setting the designMode property...

MyWin.designMode = "On";

"sam" <mq****@rediffmail.com> wrote in message
news:13*****************************@phx.gbl...

Hi

Just encountered a strange problem and wonder if it is a
bug ? I have the following piece of code....

try
{
IHTMLDocument2 MyDoc = (IHTMLDocument2
MyWebBrowser.Document;
IHTMLWindow2 MyWin = (IHTMLWindow2 ) MyDoc.open
("","_TEST_","","");

MyWin.document.writeln("line #1");
MyWin.document.writeln("line #2");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}

This opens the new WebBrowser, and writes the "line #1"
into it. But while writing the second line it throws an
exception "access denied"
Seems like I am allowed to access the "document" property
of the "IHTMLWindow2" only once.
If I try to access it again, I get this exception.

I found a work around.....
Basically I extract the MyWin.document into a variable of
IHTMLDocument2 and then invoke the writeln().
try
{
IHTMLDocument2 MyDoc = (IHTMLDocument2)
IWeb2.Document;
IHTMLWindow2 MyWin = (IHTMLWindow2 ) MyDoc.open
("","_TEST_","","");
IHTMLDocument2 MyDoc2 = (IHTMLDocument2)
MyWin.document;

MyDoc2.writeln("line #1");
MyDoc2.writeln("line #2");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
This works, but it is not foolproof. if I try to access
MyWin.document again at some other time... eg when I
invoke the function again, I still get the exception.

Anybody any clues?

TIA
sam

Nov 15 '05 #2
"sam" <mq****@rediffmail.com> wrote in news:1385101c3c226$4493d270
$a*******@phx.gbl:

Hi

Just encountered a strange problem and wonder if it is a
bug ? I have the following piece of code....
[...]
This works, but it is not foolproof. if I try to access
MyWin.document again at some other time... eg when I
invoke the function again, I still get the exception.

Anybody any clues?

TIA
sam


Hi Sam,

You have to Wait for the document to load, to be able to write to it.
There's a OnLoadFinished Event on the IHTMLDocument. You should connect to
the event and only start your writing when this event ahs been fired.

Greets
Peter

--
------ooo---OOO---ooo------

Peter Koen - www.kema.at
MCAD MCDBA
CAI/RS CASE/RS IAT

------ooo---OOO---ooo------
Nov 15 '05 #3
sam
Hi Peter,
You have to Wait for the document to load, to be able to

write to it.

I dont think it is a load problem because if I do the
following then it works like a charm...
MyDoc2 = (IHTMLDocument2)MyWin.document;
MyDoc2.writeln("line #1");
MyDoc2.writeln("line #2");

The problem is if I EVER again try to access
MyWin.document, it gives me the "access denied" exception.

TIA
sam
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Robert May | last post by:
I have an application that uses the Ax web browser object. When I call the IHTMLElement.click() method on an input button (<input type="submit"> or <input type="button">), the click fires...
4
by: Lars-Erik Aabech | last post by:
Hi! I've been walking in extacy since reading the article about test automation with IE in the latest MSDN mag. (http://msdn.microsoft.com/msdnmag/issues/05/10/TestRun/default.aspx) After a...
3
by: ddd | last post by:
I am trying to use MSHTML without the webbrowser and I am having a few problems. Right now all I am trying to do is load an URL(html page) and access its innerhtml. What I have is: Dim doc As...
11
by: Lucky | last post by:
hi guys, i need to parse html data that i've got from "Inet" object in vb6. now i want to prase the html data. here i got 2 options. one is MSXML and other is MSHTML. i tried both of them but i...
0
by: Laurent Lequenne | last post by:
Hello All, I'm currently developing a free windows Scrabble (in french :)) application that uses extensively the WebBrowser class of NET 2.0 for configuration, and data browsing. It works 100%...
6
by: Angel | last post by:
I am using coolmenus 4, frames version by DHTMLcentral.com. When I click on any of the submenus, I get an "Permission Denied" error. There after the menus stop working. The cursor on the menu...
0
by: PD | last post by:
To whom it may concern, I am using Microsoft.mshtml to parse HTML, it runs fine on my development XP Pro box. After I deployed it onto windows 2003 server, I always get error message as follows:...
0
by: timeline | last post by:
VB-WEB: proint Job Name is about:blank followed by content to print C#-APP: Sending a Job to the Printer with Crystal Reports I am using mshtml.HTMLDocumentClass docObject=new...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.