javascript - CSS not applying in bookmarklet -
i'm creating simple bookmarklet (never done before) , while script executes fine (doesn't right now), css style sheet gets embed doesn't apply html.
the activation link follows (domain changed):
<a href="javascript:(function(){document.head.appendchild(document.createelement('script')).src='http://www.mydomain.co.uk/cloudlr/app/js/cloudlr.js?rand=' + math.floor(math.random()*99999);})();">do this</a>
then script called is:
if (typeof jquery == 'undefined') { appendjquery(); } else { jsversion = $().jquery; versionarray = jsversion.split('.'); if (versionarray[1] < 6) { appendjquery(); } else { runthis(); } } function appendcss() { var cloudlrcss = document.createelement('link'); cloudlrcss.type = 'text/css'; cloudlrcss.href = 'http://www.mydomain.co.uk/cloudlr/app/css/screen.css'; cloudlrcss.media = 'all'; document.head.appendchild(cloudlrcss); } function appendjquery() { var cloudlrjs = document.createelement('script'); cloudlrjs.type = 'text/javascript'; cloudlrjs.onload = runthis; cloudlrjs.onreadystatechange = function () { if (this.readystate == 'loaded' || this.readystate == 'complete') { runthis(); } } cloudlrjs.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'; document.head.appendchild(cloudlrjs); } function runthis() { appendcss(); $(document).ready(function() { $("img").each(function() { var $this = $(this); var imagewidth = $(this).width(); $(this).before(imagewidth); }); var cloudlroverlay = '<div id="cloudlr-content">this content.</div><div id="cloudlr-overlay"></div>'; $("body").append(cloudlroverlay); }); }
hopefully that's pretty straightforward.
the scripts execute fine (jquery) no css applied. if view "generated source" can see css inserted fine , link file works. i'm not sure what's going on.
i'm new , welcome additional recommendations on best practices solution problem.
many thanks, michael.
$("img").each(function(i,n) { var $this = $(n);//don't know why here hey var imagewidth = $(n).width(); $(n).before(imagewidth); });
this common mistake ... think
Comments
Post a Comment