Jump to content

Two Similar JS Links - Why is one not working?


tec-4

Recommended Posts

Hello Everyone,

 

Have 2 links on a page that I am trying to manipulate to do the same thing (add a bookmark to a database).  The first link below works fine and adds the bookmark if it is not currently in the DB and notifies you if it is in the DB....the other one, with the slight modifications does not seem to do anything that I can notice and shows no response and does not add the bookmark to the DB...perhaps what I am trying to do is not valid JS....

 

What I have thus far:

 

This one works:

 

<a href="javascript:(function(){var jsScript=document.createElement('script');
jsScript.setAttribute('type','text/javascript');
jsScript.setAttribute('src', '/bookmark.php?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title));
document.getElementsByTagName('head')[0].appendChild(jsScript);
})();">Bookmark this!</a>

 

This one does not work:

-the only difference is that I replaced the "location.href" with an actual URL and the "document.title" with a title name.

 

<a href="javascript:(function(){var jsScript=document.createElement('script');
jsScript.setAttribute('type','text/javascript');
jsScript.setAttribute('src', '/bookmark.php?url='+encodeURIComponent(http://example.com)+'&title='+encodeURIComponent(Add Me));
document.getElementsByTagName('head')[0].appendChild(jsScript);
})();">TEST ME - Bookmark this!</a>

 

I also tried it without the encodeURIComponent and still did not seen to take.  Is what I'm trying to do not valid? Essentially trying to make it so that I can place more than one of these links on a page and bookmark a specific item and not the actual page that I am currently viewing.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.