顯示具有 html 標籤的文章。 顯示所有文章
顯示具有 html 標籤的文章。 顯示所有文章

2014年2月15日 星期六

於CSS中使用外部的字型

 只要在CSS中加入:
 
@font-face {
    font-family: "NAME";
    src: url(font.otf);
}
 
其中「NMAE」是自訂的字型名稱,
font.otf」是字型檔的路徑與名稱。

2013年12月26日 星期四

使用JavaScript抓取動態生成的網頁

想要得到html檔案的原始碼,最直觀的做法就使用: 

document.getElementsByTagName('html')[0].innerHTML
 
 
document.documentElement.innerHTML 
 
 
document.documentElement.outerHTML

但是這樣無法得到第三方JavaScript所生成的html content

於是可以使用以下函式:
 
  function DOMtoString(document_root) {
    var html = '',
    node = document_root.firstChild;
    while (node) {
        switch (node.nodeType) {
            case Node.ELEMENT_NODE:
                html += node.outerHTML;
                break;
            case Node.TEXT_NODE:
                html += node.nodeValue;
                break;
            case Node.CDATA_SECTION_NODE:
                html += '<![CDATA[' + node.nodeValue + ']]>';
                break;
            case Node.COMMENT_NODE:
                html += '<!--' + node.nodeValue + '-->';
                break;
            case Node.DOCUMENT_TYPE_NODE:
                // (X)HTML documents are identified by public identifiers
                html += "<!DOCTYPE " + node.name
                    + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '')
                    + (!node.publicId && node.systemId ? ' SYSTEM' : '') 
                    + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';
                break;
        }
        node = node.nextSibling;
    }
    return html;
}

參數document_root,表示使用上述方法所獲取的html content。
 
顧名思義,此函式將會回傳包括JavaScript動態生成的html content

2013年12月8日 星期日

php剝去HTML、XML、php的tag

剛剛在思考如何在HTML tag裡取出想要的字串

翻了書發現有個好用的函式:

strip_tags();

EX:

$html_tag = '<a href="xxxxxxx">目標字串</a>';

$html_tag = strip_tags($html_tag);

echo $html_tag;
//在此會輸出:目標字串