开发者

Loading HTML content in via Javascript nulls my <title> tag in some instances

This is an Explorer only problem and the symptoms are:

I have links that when clicked will load in HTML chunks (none of which contain html header tags) using javascript. The html chunks are placed in various <div>s around the page, perhaps 3 different places with 3 different chunks brought in via javascript.

When these chunks load in the <title> tag of the page gets set to <title></title> for some unknown (to me) reason. I've used the IE developer toolbar to confirm this by inspecting the DOM tree.

I have other pages that do similar things but it does not seem to be a problem there.

Edit: Further inspection seems to reveal that swfObject is having something to do with it. One of the chunks I bring in has a SWF that is enabled by swfObject. If I disable the swfObject call the page no longer gets zapped.

Edit: code:

/**
* getContentIte开发者_运维问答mById()
* @itemId = string
* @contentType = string
*/
function getContentItemById(itemId, contentType, subType) {
    $j.ajax({
        type: "GET",
        cache: false,
        url: "/gallery/",
        data: "contentType=" + contentType + "&itemId=" + itemId + "&slice=itemView" + "&subType=" + subType,
        dataType: "html",
        beforeSend: function (XMLHttpRequest) {
            $j("#viewer").fadeOut();
        },
        success: function(html){
            $j("#viewer").html(html).fadeIn();
            if (itemId && contentType) {
                var state = {};
                state["itemId"] = itemId;
                $j.bbq.pushState(state, 0);
            }
           },
        error:function (xhr, ajaxOptions, thrownError){
                //alert("Error code: " + xhr.statusText);
            }
    });


Since you're using jQuery, you might as well try out .load() which is a simpler method for what you're trying to achieve.

function getContentItemById(itemId, contentType, subType) {
    var data = "contentType=" + contentType + "&itemId=" + itemId + "&slice=itemView" + "&subType=" + subType;
    $('#viewer').load('/gallery/ #'+itemId, data, function() { //oncomplete function
            if (itemId && contentType) {
                var state = {};
                state["itemId"] = itemId;
                $j.bbq.pushState(state, 0);
            });
}

Refer to the API documentation to understand the working of .load() http://api.jquery.com/load/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜