I have a rest service which accepts a URL parameter: myService/add?pageUrl=www.google.com
I’m trying to add this as a bookmark so whenever the user clicks the bookmark the current page URL is sent to my rest service.
Here is the javascript code I am using but the service is not being invoked
javascript:function savePage() {
window.open('myService/add?pageUrl=' + document.URL)
alert('Page saved');
}
savePage();
I receive the error:
Uncaught SyntaxError: Unexpected identifier
How can the above javascript be amended to so that when I add the code to a bookmark my service is invoked and the current URL the user is visiting is sent to the service?
Create bookmarklets like this:
So, in your case:
After the
javascript:section, you have a self-executing (anonymous) function:And code in there will be evaluated.
Also, make sure you’re not missing any semicolons (
;). Those will break your code in bookmarklets.