Tech-Today
C# Insert dynamic html - html injection
While creating a plugin for IE, I've encountered several problems like how to create a popup form when a certain condition has been met. And how to add dynamic css and javascript to the document page.
What I did.
In IE's DocumentComplete method you will get the url and web browser object. (Actually I've tried 2 IE framework in doing an IE plugin, spicie and add-in express). But eventually I've use add-in because spicie hasn't been updated for a long time.
How to get the doc element:
Spicie:
var webBrowser = pDisp as IWebBrowser2;
var doc2 = webBrowser.Document as IHTMLDocument2;
Add-in, readily available through HTMLDocument getter.
Add dynamic html:
var element = doc2.createElement("div");
element.innerHTML = "Hello czetsuya";
element.setAttribute("id", "myDiv", 0);
element.setAttribute("class", "myDivClass", 0);
doc2.body.insertAdjacentHTML("afterBegin", element.outerHTML);
doc2.close();
Adding js and css:
var headElem = (IHTMLElement)(doc2.getElementsByTagName("head").item(null, 0));
if (headElem != null)
{
var styleSheet = doc2.createStyleSheet("", 0);
styleSheet.cssText = @".myDivClass { cursor: move }";
}
var js = "function sayHi(alert(\"Hello czetsuya\"))";
var scriptElem = (IHTMLScriptElement)doc2.createElement("script");
scriptElem.type = @"text/javascript";
scriptElem.text = @"" + js + "";
((HTMLHeadElementClass)headElem).appendChild((IHTMLDOMNode)scriptElem);
window.execScript("sayHi()", null);
-
Html Scraping With Java
One rainy Sunday afternoon since I can't get out to go somewhere I've decided to create an organized excel file (for now) for the list of birds commonly found in the Philippines. I found a good site to start with, http://www.birding2asia.com/tours/reports/PhilFeb2010_list.html,...
-
Validation-summary-errors Div Showing Even If There Is No Error Binded To A Property
I'm working on a change password form when I encountered this strange behavior from mvc3. I created a simple form and change password model with 3 fields (old, new, confirm password). Then I extended ValidationAttribute to validate the password's...
-
Jquery Document.ready $("#controlid") Is Null Error
I'm working on a script that uses jquery and it's working normally on a simple page that I made. However when I create a master page in c# and put the jquery code in the page that extends the master page I get this error: $("#controlId") is null...
-
Unable To Update The Entityset '' Because It Has A Definingquery And No
Problem: Unable to update the EntitySet '' because it has a DefiningQuery and no element exists in the element to support the current operation. Solution: This problem has been plaguing me again and again :-D. Usually when I'm working on...
-
This Article Explains Some Of The Browser Specific Stylesheet Hacks (like Ie Only, Firefox, Etc) That Can Be Used In Developing A Web Application On Different Browsers
Web UI design for beginners may be complicated than it seems specially if your developing cross browser application. For example building a web app compatible with firefox, ie6 and ie7. One ways is to simply load the appropriate css file using: <!--[if...
Tech-Today