Cant execute javascript onto a webpage

Add-in Express™ Support Service
That's what is more important than anything else

Cant execute javascript onto a webpage
getting "Exception from HRESULT: 0x80020101" 
Deepika Shukla




Posts: 11
Joined: 2011-02-11
Hi Team!

Please help me out of the strange problem I am facing. I want to display tab orders on the web-page and for this I want to execute a JavaScript function on the button click of my toolbar. But I am getting “Exception from HRESULT: 0x80020101”

I came through your site http://www.add-in-express.com/support/addin-c-sharp.php#internet-explorer
And found the topic “How to run and replace a script (JavaScript, JScript or VBScript) on an HTML page in IE 6 or 7”,downloaded the sample(also Attached with this mail) you have provided and when I make it run I again got following error:

See the end of this message for details on invoking
Just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************

System.Runtime.InteropServices.COMException (0x80020101): Exception from HRESULT: 0x80020101

at mshtml.HTMLWindow2Class.IHTMLWindow2_execScript(String code, String language)

at MyIEAddon6.MyIEToolBar1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Deepika.Shukla\My Documents\Downloads\AutoCompletee\PDFextractor\ie-runtime-scripting-vs2005cs\MyIEAddon6\MyIEToolBar1.cs:line 113

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** JIT Debugging **************

To enable just-in-time (JIT) debugging, the .config file for this

application or computer (machine.config) must have the

jitDebugging value set in the system.windows.forms section.

The application must also be compiled with debugging

enabled.



For example:



<configuration>

<system.windows.forms jitDebugging="true" />

</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Please help me out of this error!

It’s very urgent.

Thanks!
Deepika


[COLOR=red][COLOR=red][FONT=Impact]
Posted 18 Apr, 2011 01:31:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Hi Deepika.

In the example, you need to press the ‘Replace the Script’ button before you run the test script. Also, you need to open a web page with scripts, e.g. www.google.com. Please test it again.
Posted 18 Apr, 2011 12:45:02 Top
Deepika Shukla




Posts: 11
Joined: 2011-02-11
Thanks Sergey! It worked!
Posted 22 Apr, 2011 07:29:59 Top
Deepika Shukla




Posts: 11
Joined: 2011-02-11
Hi Team!



Thanks for the quick reply! The test project is working fine. But can you please help me out of the problem I am facing.

I want to display tab orders on the web-page and for this I want to execute a JavaScript function on the button click of my toolbar.

I am getting “Exception from HRESULT: 0x80020101”
The code is as follows :


private void button2_Click(object sender, EventArgs e)
        {
            mshtml.HTMLDocument doc = this.HTMLDocument;
            if (doc != null)
            {
                mshtml.IHTMLElementCollection elementCollection1 = doc.getElementsByTagName("script");
                if (elementCollection1 != null)
                {
                    for (int i = 0; i < elementCollection1.length; i++)
                    {
                        mshtml.IHTMLScriptElement scriptElement = elementCollection1.item(i, i) as mshtml.IHTMLScriptElement;
                        if (scriptElement != null)
                        {
                            if (scriptElement.text != null)
                            {
 X scriptElement.text = "function taborder(){var b=0;t=document.getElementsByTagName('*');{ for(i=0;i<t.length;i++) {if(t[i].tagName.toLowerCase()=='a'&&t[i].innerHTML!=''||t[i].tagName.toLowerCase()=='iframe'||t[i].tagName.toLowerCase()=='object'||(t[i].tagName.toLowerCase()=='input'&&t[i].type!='hidden')||t[i].tagName.toLowerCase()=='textarea'||t[i].tagName.toLowerCase()=='select'||(t[i].tagName.toLowerCase()=='img'&&t[i].useMap)){if (t[i].tabIndex) { if (t[i].tabIndex>b||t[i].tabIndex==b)  { b=t[i].tabIndex; } }} }for(i=0;i<t.length;i++) { if((t[i].tagName.toLowerCase()=='a'&&(t[i].innerHTML!=''||t[i].href!='')||t[i].tagName.toLowerCase()=='iframe'||t[i].tagName.toLowerCase()=='object'||(t[i].tagName.toLowerCase()=='input'&&t[i].type!='hidden')||t[i].tagName.toLowerCase()=='textarea'||t[i].tagName.toLowerCase()=='select'||(t[i].tagName.toLowerCase()=='img'&&t[i].useMap))&&!t[i].tabIndex) { b+=1; t[i].insertAdjacentHTML('AfterEnd','<span st yle='color:red;background:#ffefd5;font:bold .8em arial;padding:4px;'><strong>'+b+'</strong></span>'); t[i].style.border='1px dashed red'; if (t[i].parentNode.style.display=='none'){ t[i].parentNode.style.display='block'} } }}}";
                            }
                            Marshal.ReleaseComObject(scriptElement);
                        }
                    }
                    Marshal.ReleaseComObject(elementCollection1);
                }
            }
        }


Thanks!

Deepika
Posted 25 Apr, 2011 00:11:34 Top
Sergey Grischenko


Add-in Express team


Posts: 7224
Joined: 2004-07-05
Hi Deepika.

Probably you just need to add a new script instead of replacing all scripts on the web page.
You can also rewrite the script in C# and call the C# code from the event handler of the button.
Posted 26 Apr, 2011 04:28:33 Top