检测.append是否不可能?

时间:2010-10-06 19:54:27

标签: javascript jquery lightbox bookmarklet

我正在创建一个模态窗口书签,可让您快速向我的网站添加内容。除非非HTML内容,它一切正常和花花公子,因为它不能将数据附加到正文。相反,我想做一个简单的location.href。

当前代码:

if (typeof jQuery == 'undefined') {
    var jQ = document.createElement('script');
    jQ.type = 'text/javascript';
    jQ.onload=runthis;
    jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
    document.body.appendChild(jQ);
} else {
    runthis();
}

function runthis() {
    if ($("#baasframe").length == 0) {

            $("body").append("\
            <div id='baasframe'>\
            <div id='baasframe_veil' style=''>\
                <p>Loading...</p>\
            </div>\
            <iframe src='http://example.com/submit.php?url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)+"' onload=\"$('#baasframe iframe').slideDown(500);\">Enable iFrames.</iframe>\
            <style type='text/css'>\
                #baasframe_veil { display: none; position: fixed; width: 100%; height: 100%; top: 0; left: 0; background-color: rgba(0,0,0,.50); cursor: pointer; z-index: 900; }\
                #baasframe_veil p { color: white; font: normal normal bold 20px/20px Helvetica, sans-serif; position: absolute; top: 50%; left: 50%; width: 10em; margin: -10px auto 0 -5em; text-align: center; }\
                #baasframe iframe { display: none; position: fixed; top: 10%; left: 10%; width: 80%; height: 80%; z-index: 999; border: 10px solid rgba(0,0,0,.5); margin: -5px 0 0 -5px; }\
            </style>\
        </div>");
        $("#baasframe_veil").fadeIn(750);
    }

$("#baasframe_veil").click(function(event){
    $("#baasframe_veil").fadeOut(750);
    $("#baasframe iframe").slideUp(500);
    setTimeout("$('#baasframe').remove()", 750);
});
}

function getSelText() {
var s = '';
if (window.getSelection) {
    s = window.getSelection();
} else if (document.getSelection) {
    s = document.getSelection();
} else if (document.selection) {
    s = document.selection.createRange().text;
}
return s;
}

如何让它检测到数据追加不起作用并将其指向location.href呢?

很有责任,

丹尼斯

1 个答案:

答案 0 :(得分:1)

使用document.documentElement