Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Thursday, June 19, 2014

How to get dropdown list from html by Html Agility Pack

private List GetDropdownList(string HtmlSource, string selectName)
        {
            HtmlDocument doc = new HtmlDocument();
            HtmlNode.ElementsFlags.Remove("option");
            doc.LoadHtml(HtmlSource);
            return doc.DocumentNode.SelectNodes(string.Format("//select[@name='{0}']//option", selectName)).Select(v => v.Attributes["value"].Value).ToList();
        }
Need to add HtmlNode.ElementsFlags.Remove("option");
before loading html source.

Friday, June 6, 2014

How to get list of div that contains specific class name in Html Agility?

            var DivListContainSpeciicClassName = htmlDoc.DocumentNode.Descendants("div").Where(
                d => d.Attributes.Contains("class")
                &&
                d.Attributes["class"].Value.Contains("cssClassName"));

Wednesday, April 23, 2014

Play video in Html 5




Reference:
http://en.wikipedia.org/wiki/HTML5_video

Thursday, December 5, 2013

How to extract text from html tages?


By HtmlAgilityPack

HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(htmlstring);
            string text = doc.DocumentNode.InnerText;
            text = Regex.Replace(text, @"\s+", " ").Trim();

Tuesday, November 26, 2013

How to enable html source button on tinyMCE?

Add "code" into plugins list, then add "code" into button array
        tinyMCE.init({
            // General options
            mode: "textareas",
            plugins: "spellchecker,code",
            theme : "advanced",
            theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,link,unlink,code",
            theme_advanced_buttons2 : "code",
        });

Wednesday, November 13, 2013

Prevent Duplicate Form Submission

http://shaiekh.com/home/prevent-duplicate-form-submission/

- Disable submit button
- PRG (Post/Redirect/Get)
- Unique token in the session

Thursday, November 7, 2013

How to remove nodes in HTMLAgilityPack? Such as remove all of invisible div?

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);
            var Divs = doc.DocumentNode.SelectNodes("//div[(contains(@style,'display:none'))]");
            if (noneDivs != null)
            {
                foreach (var one in noneDivs.ToList())
                {
                    one.Remove();
                }
            }

Friday, May 24, 2013

What's the difference between IFrame and Frameset?

Frameset is dead and long live iframe :)
Frameset replace body elment. And ifeame can be anywhere in the body. Also frameset is NOT supported in HTML 5

http://www.w3.org/TR/html401/frameset.dtd

Tuesday, May 7, 2013

What is the difference between Html button and input type=button?


Almost same, but button with more rendering abilities.


Buttons created with the BUTTON element function just like buttons created with the INPUT element, but they offer richer rendering possibilities: the BUTTON element may have content. For example, a BUTTON element that contains an image functions like and may resemble an INPUT element whose type is set to “image”, but the BUTTON element type allows content.
The Button Element - W3C

References:
http://stackoverflow.com/questions/469059/button-vs-input-type-button-which-to-use
http://web.archive.org/web/20110721191046/http://particletree.com/features/rediscovering-the-button-element/

Friday, May 3, 2013

How to extract text from html by HtmlAgilityPack?


            string htmlstring ="

adsasd

"; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(htmlstring); foreach (var script in doc.DocumentNode.Descendants("script").ToArray()) script.Remove(); foreach (var style in doc.DocumentNode.Descendants("style").ToArray()) style.Remove(); string ExtractedText = doc.DocumentNode.InnerText;

Friday, February 22, 2013

How to check one web site is HTTP compression enabled?

1. By this website
http://www.whatsmyip.org/http-compression-test/

2. By Chrome f12 tool/Firefox Firebug
Checking reponse headers if exists: Content-Encoding:gzip

(IE f12 tool does not display this header)

Friday, February 15, 2013

How to extract Javascript from html source by HtmlAgilityPack

            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(html);
            var scriptList = htmlDoc.DocumentNode.Descendants()
                .Where(n => n.Name == "script" );

Tuesday, January 29, 2013

How to display PDF in html?

By Google PDF viewer and put into iframe