[Django]-Jquery image bookmarklet not working in Django

2đź‘Ť

âś…

I followed the same book with the same examples but didn’t had any trouble. Make sure your dashboard.html file is referring to the correct javascript file. If nothing works try to add the bookmark manually, you can see how that’s done over here http://www.howtogeek.com/189358/beginner-geek-how-to-use-bookmarklets-on-any-device/ it’ll sure to work.
And answer to your last question, Indentation is not as important in JavaScript as it’s in Python, as python doesn’t use any curly braces “{}” or semi-colons “;”. But you can write your entire javascript code in a single line and it’ll work because your using curly braces everywhere to tell which line of code ends where.

👤anas munir

1đź‘Ť

I agree with all the above. In addition, the following:

  1. Error I noticed in the book:

In bookmarklet-launcher.js the js function being called from bookmarklet.js is called myBookmarklet(), however there is no function called this way in bookmarklet.js. So, you may want to use the same name in both js files.
Practically speaking however, the bookmarklet will always work because, not finding a myBookmarklet function in memory, bookmarklet-launcher.js appends the bookmarklet.js script to the body element and, being bookmarklet.js a self-invoking function, its content executed (without the need it to being called). There are some additional interesting technicalities here (the key function in bookmarklet.js is not self invoking but it will anyway be always called because of the script checking whether jQuery is present…) but ok, this is more relevant for those busy with the mentioned book (Django 2 by example).

  1. Check whether bookmarkled, once you click on it, is added to the
    current webpage:

2.1. Open devtools (F12 on Chrome) and check e.g. in the html head element whether you find the newly added link element containing the css attribute and/or in the body element whether you find the script element containing the reference to the bookmarklet.js file.

2.2. Alternative: Add an alert message on top of the bookmarklet.js script so that it will be launched if it is correctly loaded. Example:

(function(){
    alert('bookmarkled loaded!');
    var jquery_version =...
👤Oxfos

0đź‘Ť

Make sure you’re trying to use it on a HTTP site only. Since you’re serving from same protocol. HTTPS site would always tell say: There is a problem loadingbyour jquery. That’s how I solved mine.

0đź‘Ť

dude.I have solved the problems I met like you.

The most important thing is that noticing the syntax error(without warnings),mainly caused by ignoring blank.
for example, in the line:

 jQuery('#bookmarklet .images').append('<a href="#"><img src="'+image_url+'"/></a>');

between #bookmarklet and .images should lie a blank space,because of jquery syntax rules(meaning to search tag with id of bookmarklet and search tag with class equaling images within result previously).

Another two places worth notice are codes containing #bookmarklet .images a and #bookmarklet #close,requiring blank spaces between filter condition.

That’s where I found I made mistaks mainly after studying syntax of jquery.

You’d better compare your codes with codes already loaded up to github by someone to make sure there are no more little errors(such as spelling).

👤chenxingping

Leave a comment