检测 .append 是否不可能?
我正在创建一个模态窗口书签,可让您快速将内容添加到我的网站。除了非 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?
非常感谢,
丹尼斯
I'm creating a modal window bookmarklet that allows you to quickly add content to my website. It all works fine and dandy except for non-html content, because then it cannot append data to the body. Instead, I'd like to do a simple location.href.
Current code:
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;
}
How can I make it detect that the appending of data didn't work and direct it to a location.href instead?
Much obliged,
Dennis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
document.documentElement
。Use
document.documentElement
.