How to block specific IE elements to show

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

How to block specific IE elements to show
 
hua shi




Posts: 7
Joined: 2012-05-03
I want to block some pictures(.jpg) and .js in a web page.
How to block or filter specific HTML Element to be requested? Maybe I need to filter by some regular expression.
thank you
Posted 03 May, 2012 21:55:19 Top
hua shi




Posts: 7
Joined: 2012-05-03
it's not like this thread
http://www.add-in-express.com/forum/read.php?FID=5&TID=5098

I just want to block specific elements , like images, java script to be loaded by IE.
some software hide this elements, but I don't want them to be loaded, to speed IE. But i don't want to block ALL, only images I set up.
Posted 04 May, 2012 01:55:59 Top
Eugene Astafiev


Guest


Hi Hua Shi,

Please try to handle the DocumentComplete event of the add-on module and remove forbidden html elements from the event handler.
Posted 04 May, 2012 08:36:33 Top
hua shi




Posts: 7
Joined: 2012-05-03
I am sorry, How to remove them? can you show me some example codes?
http://www.google.com
How to remove the google logo? the id is hplogo
HTMLDocument.getElementById("hplogo")
Posted 05 May, 2012 11:33:42 Top
Eugene Astafiev


Guest


Hi Hua Shi,

Sure. I will prepare a sample add-in for you today.
Posted 07 May, 2012 03:46:46 Top
hua shi




Posts: 7
Joined: 2012-05-03
Thank you.
Looking forward to it/
Posted 07 May, 2012 08:44:15 Top
Eugene Astafiev


Guest


Hi Hua Shi,

I have just tested the following code on my PC with Internet Explorer 9 and it works like a charm:

private void IEModule_DocumentComplete2(object pDisp, string url, bool rootDocLoaded)
{            
    if (url.Equals("https://www.google.com/"))
    {   
        mshtml.IHTMLElement element = HTMLDocument.getElementById("hplogo");                
        if (element != null)
        {
            mshtml.IHTMLDOMNode node =null;
            mshtml.IHTMLElement parent = null;
            mshtml.IHTMLDOMNode removed = null;
            try
            {
                node = element as mshtml.IHTMLDOMNode;
                parent = element.parentElement;
                removed = ((mshtml.IHTMLDOMNode)parent).removeChild(node);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                Marshal.ReleaseComObject(node);
                Marshal.ReleaseComObject(parent);
                Marshal.ReleaseComObject(removed);
            }
        }                
    }
}


Please let me know the results of your tests in any case.
Posted 07 May, 2012 09:01:19 Top
hua shi




Posts: 7
Joined: 2012-05-03
thank you.
I will try to translate them to vb.net and test.
Posted 07 May, 2012 09:05:18 Top
Eugene Astafiev


Guest


Hi Hua Shi,

You can use any code converter. For example, I have used http://www.developerfusion.com/tools/convert/csharp-to-vb/ one.

Private Sub IEModule_DocumentComplete2(pDisp As Object, url As String, rootDocLoaded As Boolean)
	If url.Equals("https://www.google.com/") Then
		Dim element As mshtml.IHTMLElement = HTMLDocument.getElementById("hplogo")
		If element IsNot Nothing Then
			Dim node As mshtml.IHTMLDOMNode = Nothing
			Dim parent As mshtml.IHTMLElement = Nothing
			Dim removed As mshtml.IHTMLDOMNode = Nothing
			Try
				node = TryCast(element, mshtml.IHTMLDOMNode)
				parent = element.parentElement
				removed = DirectCast(parent, mshtml.IHTMLDOMNode).removeChild(node)
			Catch ex As Exception
				System.Windows.Forms.MessageBox.Show(ex.Message)
			Finally
				Marshal.ReleaseComObject(node)
				Marshal.ReleaseComObject(parent)
				Marshal.ReleaseComObject(removed)
			End Try
		End If
	End If
End Sub
Posted 07 May, 2012 09:13:49 Top
hua shi




Posts: 7
Joined: 2012-05-03
the code HIDE the google logo, but the images is still be loaded behind.
I want to block them, no loading.
User added an image
Posted 07 May, 2012 09:19:47 Top