AJAX from the built-in Safari script extension

I am trying to extend shorturl using the API in the entered script in the Safari extension:

$.getJSON('http://api.longurl.org/v2/expand?format=json&url=' + encodeURIComponent(href) + '&callback=?', function(data) { console.log(data); }); 

And I get the following error:

 ReferenceError: Can't find variable: jQuery15103411371528636664_1298845652395 

I tried a different API and got the same error, so I know this is not the case. Also, if I execute the same code from the console, I get a successful response. So this should be due to the fact that inside the implemented Safari script extension.

Any ideas?

+4
source share
1 answer

I believe you should add jQuery to the plugin first. Here is an example of how:

 var newElement = document.createElement("script"); newElement.type = "text/javascript"; newElement.src = "//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"; document.body.insertBefore(newElement, document.body.firstChild); 

Then you can do jQuery on the tab using your plugin .;)

-1
source

Source: https://habr.com/ru/post/1341558/


All Articles