Like the Delicious submission bookmark-let, I'd like to have some standard JavaScript I can use to submit any visited URL to a 3rd party site when that's possible by URL. Suggestions?
For example, I've been using
javascript:void(location.href="="+encodeURI(location.href))
so far but wonder if there's something more sophisticated I could use or better practice.
Like the Delicious submission bookmark-let, I'd like to have some standard JavaScript I can use to submit any visited URL to a 3rd party site when that's possible by URL. Suggestions?
For example, I've been using
javascript:void(location.href="http://www.yacktrack./home?query="+encodeURI(location.href))
so far but wonder if there's something more sophisticated I could use or better practice.
Share Improve this question edited Jun 25, 2017 at 10:29 ɢʀᴜɴᴛ 32.9k15 gold badges122 silver badges114 bronze badges asked Sep 10, 2008 at 15:35 Marshall KirkpatrickMarshall Kirkpatrick 2421 gold badge4 silver badges9 bronze badges3 Answers
Reset to default 2Do you want something exactly like the Delicious bookmarklet (as in, something the user actively clicks on to submit the URL)? If so, you could probably just copy their code and replace the target URL:
javascript:(function(){
location.href='http://example./your-script.php?url='+
encodeURIComponent(window.location.href)+
'&title='+encodeURIComponent(document.title)
})()
You may need to change the query string names, etc., to match what your script expects.
If you want to track a user through your website automatically, this probably won't be possible. You'd need to request the URL with AJAX, but the web browser won't allow Javascript to make a request outside of the originating domain. Maybe it's possible with iframe
trickery.
Edit: John beat me to it.
document.location = "http://url_submitting_to.?query_string_param=" + window.location;
Another option would be to something like this:
<form action="http://www.yacktrack./home" method="get" name="f">
<input type="hidden" name="query" />
</form>
then your javascript would be:
f.query.value=location.href; f.submit();
or you could bine the [save link] with the submit like this:
<form action="http://www.yacktrack./home" method="get" name="f" onsubmit="f.query.value=location.href;">
<input type="hidden" name="query" />
<input type="submit" name="Save Link" />
</form>
and if you're running server-side code, you can plug in the location so you can be JavaScript-free:
<form action="http://www.yacktrack./home" method="get" name="f">
<input type="hidden" name="query" value="<%=Response.Url%>" />
<input type="submit" name="Save Link" />
</form>