2010-10-06 129 views
0

我正在创建一个模式窗口小书签,它允许您快速将内容添加到我的网站。除了非HTML内容外,它都可以正常工作,因为它不能将数据附加到主体。相反,我想做一个简单的location.href。检测.append是否不可用?

当前代码:

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

使用document.documentElement

+0

嗨Eli,我试过这个,但它不起作用,你有没有试过,看看它是否有效? – FLX 2010-10-07 09:58:26

+0

我认为你的问题是你在脚本标签上使用'onload',我怀疑许多浏览器会支持。 – 2010-10-09 16:11:05