Mask or hide an affiliate URL? - javascript

I would like to share an affiliate link that points to an iOS app in Apple's Appstore. Is it possible to mask it or create a sort of proxy to it, in a way that another user can not access it directly while at the same time maintaining its function as an affiliate link?

Its not possible to completely hide it, but it would be possible to hide the url from non-technical users using a few tricks.
You can put an onclick event handler on the link instead of an href attribute so that the user cannot get the URL by right-clicking the link.
Here's a sample code at jsfiddle.

Related

Track onclick actions

I need to build Google Chrome plugin, what will track all clicks on all links on all pages.
After click on link, instead of page opening plugin must catch click, plugin must obtain href attribute of the clicked link, change something in this URL and open page with new, changed URL.
Is it possible to make?
With the Content Scripts you can pass your own JS library into any (or particular) page, intersect clicks and prevent defaults (with regular JS API) and finally you can pass link back to the background page and use chrome.tabs API to open the window.

Mobile Redirect URL with Javascript

I'm basically trying to make one link on my page and when the user clicks the link it will direct to one of these links depending on what device they are coming from.
So the link says "Download Now" and I need it to launch these URL's depending on the user agent device
If Android then android.com
If Windows then windows.microsoft.com
If Apple then apple.com
I am trying to avoid using PHP to accomplish this.
Any suggestions?
You can use the navigator.userAgent and created a method to search for android/iPhone/WindowsPhone etc string within the userAgent string. You'll need to research these online and get a list of all mobile devices and redirect based on that.
You can use the User Agent from JavaScript and intercept clicks on links, redirecting to a page depending on what User Agent is detected. Here's some code to give you an idea: Change link destination based on whether user has mac or PC. Here's a link to various User Agents which may be useful: List of User Agents
Make sure that the link still has a valid href attribute though in case the user disables JavaScript. Another possible approach is modifying all the links: changing the href attribute on page load to fit the User Agent.

Tracking Social Button Clicks in Javascript

On a website, I have some social buttons (tweet, facebook like, google+1, ..). Most of them are inserted using an iframe.
The task is to track use interaction with those buttons: if someone +1'ed the content - and AJAX request should update my local statistics on the server.
However, with JS I can't access the contents of the iframe due to security restrictions: can't bind 'click' event.
How do I track clicks on those social buttons, then?
Possible solutions:
Bind 'click' to the iframe object itself: it does not work.
Add buttons inline, w/o an iframe. No go: I should also display the number of likes for every button.
Try to use Social Service APIs to insert without an iframe. Not all services support this.
You can't. If you could catch clicks on them you could also trigger clicks on them which would be pretty bad (imagine porn sites making you "like" them automatically).
The only thing you can do is using the APIs of the various sites to retrieve the number of people who liked/+1'd/etc. your site.
Most of the social buttons from the main companies enable your Javascript to detect when the button has been pressed. They usually do this via Javascript events.
In other words, they'll tell your code that they've been pressed, you don't have to detect it on your own.
Twitter
info on their javascript events
Facebook
You need to use the XFBML version of the button. From the Facebook Like button FAQ
How do I know when a user clicks a Like button?
If you are using the XFBML version of the button, you can subscribe to the 'edge.create' event through FB.Event.subscribe.
Google +1
See the callback parameter in their docs. See section +1 Tag Attributes. You provide a Javascript (JS) function to their button. Your JS is then called by them when the button is pushed. Easy!

How to give user trying to copy URL other URL than the A HREF value?

I use skeleton framework to sketch tabs inside IFRAME widget. Each tab has code like this:
<a class="active" href="#skeletonTab0" target="_top">Name of tab</a>
href pointed to #.... is required for the menu to work.
When user right clicks on this tab and selects "copy URL" he gets the URL of the widget host http://dummyhost.com/index.php#skeletonTab0.
But because the widget is embedded on site http://importantnews.com i would like him to copy URL to:
http://importantnews.com/index.php?showTab=0
Is there any way to make it so that a will have href pointed to #skeletonTab0 but when user tries to copy the URL he will get proper URL on important news?
Basically the question is if i can provide user trying to copy URL from a href other href than actual href?
EDIT: Today, i've found a working example of something similar to what i try to obtain, but still figure out how to make this work for me.
Look at this site:
https://plus.google.com/100784670873737717716/posts/PAEa7sFcKMS
When you click "What i learned" it redirects you to http://www.readwriteweb.com.
When you copy the URL of this link you get http://www.readwriteweb.com.
But when you click the link plus.url.google.com* redirecting to http://www.readwriteweb
Have you any ideas?
Not really, no. What you could do is have the link point to http://importantnews.com/index.php?showTab=0 but register an onclick listener so that when the link is clicked, the default action (i.e. going to that link) is cancelled and replaced by your desired action.

How do you hide the URL when you hover a hyperlink?

When you hover over a hyperlink you see in the corner of your browser the url you're gonig to. I'm using javascript to navigate through my tabs div. When I hover over the tab I see the url. I would like to hide this. Is this possible?
Link to example
Don't do it! Clients like to see where links are going. This behavior isn't up to you.
The only thing you could reasonably do is set the link to go to nowhere, and set the onclick attribute with sourcecode that does a window.location.
If you don't use the "href" attribute, the link won't show up.
Simply do this:
<a id="tab1">Tab 1</a>
$('#tab1').click(function(event) {
switchTabs();
});
This will register a click event (using jQuery) on the link without displaying any URL to the user. This is the proper way for handling links that don't redirect the user.
Hide Text
Then in that function you can have a switch case statement which uses window.location to send the user to another page.
Downsides to this include alienating your users which disable Javascript, and search engines probably won't follow this link.

Categories