小书签实施
我正在重新表述我的整个问题,这个问题以前听起来很荒谬,但现在这个问题更加理性了。 我正在实现一个书签(来自此链接的教程 http ://net.tutsplus.com/tutorials/javascript-ajax/create-bookmarklets-the-right-way/ )有点类似于 bitly 侧边栏 请参阅链接:http://bitly.com/pages/sidebar 一旦用户将小书签添加到收藏夹/书签栏,当用户单击小书签时,我的弹出窗口将打开,其中包含各种字段供用户添加。目前,我正在使用静态 html 标记在本地计算机中执行此操作。目前我还没有包含弹出窗口所需的 CSS,但很快就会实现它。 但我面临着不少挑战: 这是我的代码: Bookmarklet
<a href='javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){alert("div is not hidden");var content_script = $("<script></script>").attr("src","bookmarklet_content.js").attr("type","text/javascript").attr("language","Javascript");$("head").append(content_script);});'>Edit</a>
通过 bookmarklet 包含的 JS 文件
var html_content = '';
var isUserSignedIn = 1;
if(isUserSignedIn) {
html_content = 'markup for my popup div';
$('body').append(html_content);
if($("#tbarAddtoBrfPopup")) {
alert('element identified');
} else {
alert('failed to identify');
}
$("#divname").find(".pagename_parent").find(".pagetitletextfield").val(document.title);
var success_popup = 'another huge bunch of markup';
$('body').append(success_popup);
}
else {
html_content = 'another pop up for signing in';
$(html_content).insertAfter($('body'));
}
$("#popup1_submit_button").live('click',function(){
$("#current_popup").hide();
$("#Success_p0\opup").show();
});
// close buttons in my popup
$(".close").live('click',function(){
$(this).parent().parent().hide();
});
我已经感受到了在标记中转义内容以防止格式不正确的错误的热度(这花了我一个小时来查找和修复) ),以及一些特殊字符,例如表示关闭的“x”,以有趣的 ascii 艺术风格显示。即使现在我也收到 var html_content=''; 行的语法错误我对此一无所知。
请告诉我是否有更好的程序从外部文件中获取 html 和 js 并毫无问题地显示。
另外,这个弹出窗口对于我的机器中的本地页面工作得很好...当我对任何公共页面使用书签时,似乎根本没有加载外部js。看来我在这里遗漏了一些东西。 编辑猜测是因为调用我的js文件及其相对路径。
任何形式的帮助或建议(除了我应该退出编码)都会很棒。 谢谢!!
I'm rephrasing my entire question which previously sounded absurd with this one which is a bit more rational.
I'm implementing a bookmarklet (tutorials from this link http://net.tutsplus.com/tutorials/javascript-ajax/create-bookmarklets-the-right-way/ ) a bit similar to the bitly sidebar Refer the link: http://bitly.com/pages/sidebar
Once the user has added the bookmarklet to the fav/bookmarks bar, when user clicks on the bookmarklet my popup opens up with a variety of fields for the user to add..currently doing this in my local machine with static html markup. I haven't included the css necessary for the pop up currently but will implement it shortly.
But am facing quite a few challenges:
Here's my code:
Bookmarklet
<a href='javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){alert("div is not hidden");var content_script = $("<script></script>").attr("src","bookmarklet_content.js").attr("type","text/javascript").attr("language","Javascript");$("head").append(content_script);});'>Edit</a>
JS file included through bookmarklet
var html_content = '';
var isUserSignedIn = 1;
if(isUserSignedIn) {
html_content = 'markup for my popup div';
$('body').append(html_content);
if($("#tbarAddtoBrfPopup")) {
alert('element identified');
} else {
alert('failed to identify');
}
$("#divname").find(".pagename_parent").find(".pagetitletextfield").val(document.title);
var success_popup = 'another huge bunch of markup';
$('body').append(success_popup);
}
else {
html_content = 'another pop up for signing in';
$(html_content).insertAfter($('body'));
}
$("#popup1_submit_button").live('click',function(){
$("#current_popup").hide();
$("#Success_p0\opup").show();
});
// close buttons in my popup
$(".close").live('click',function(){
$(this).parent().parent().hide();
});
I'm already feeling the heat with escaping stuff in the markup to prevent not well-formed error( which took me an hour to find and fix), and some special characters like a 'x' for close which is displayed in a funny ascii art style. Even now i get a syntax error for line var html_content=''; which i'm clueless about.
Kindly let me know if there's a better procedure to fetch html and js from an external file and display without issues.
Also this popup works fine for local pages in my machine... when i use the bookmarklet for any public page it appears that the external js is not loaded at all. Seems I'm missing something here.
Edit guess its because of calling my js file w.r.t its relative path.
Any sort of help or suggestions(except that I should quit coding) would be great.
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我决定遵循使用 iframe 的位实现,这似乎是防止 css 和 js 混搭和混乱问题的最佳选择......
I decided to follow the bitly implementation of using an iframe which seemed to be the best possible option to prevent the css and js mashup and mess up issues...