Netzz

tips collection

NAVIGATION - SEARCH

Google Chrome blocks scripts and fonts loaded in http from page running https

When you use CDN to load scripts and fonts from a page running in https you have to use https for every external url avoiding mixing content:

https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
https://fonts.googleapis.com/css?family=Open+Sans

You can also omit the http: from the url letting the browser use the same protocol of the page.

Create XML using jQuery

With jQuery you can manipulate XHTML documents and create HTML fragments.

But you can also create XML documents and serialize them to string:

var doc = $.parseXML('<?xml version="1.0" encoding="utf-8" ?><Root xmlns="http://www.w3.org/1999/xhtml" />');
var $Root = $(doc.documentElement);
$('<cmd>').appendTo($Root).attr('Upper', 'val').text('action');
var xml=(new XMLSerializer()).serializeToString(doc)
//var xml=$("<dummy>").append($Root.clone()).html();
$(document.body).text(xml);

To be sure attributes are not lowered you have to append the element to it's parent before setting attributes.

You can also create an XML fragment in the same way:

var doc = $.parseXML('<Root />');
var $Root = $(doc.documentElement);
$('<cmd>').appendTo($Root).attr('Upper', 'val').text('action');
var xml=(new XMLSerializer()).serializeToString(doc)
//var xml=$("<dummy>").append($Root.clone()).html();
$(document.body).text(xml);