Workaround: window.status not working on FF, Chrome, IE7, Safari

Hi Guys,

Alright! so you are in same boat that I was until I did a little trick to get around this problem.

Need for using windows.status arises when you don’t want user to see

  1. You affiliate links
  2. Your advertisement links
  3. Simplified URL
  4. hide status bar onmouseover
  5. Custom message etc etc
Your use case can be totally different to the above. The technique I am going to show you has been used on couple of links on this screen. Try to hover and check out the link  below.
(affiliate link)

This stuff use to be so simple in old days when we can reliably use window.status=”whatever” so with old technique we can do something like this if I want to hide say my tracking code then I will do something like this

  1. <a href="http://jaspreetchahal.org?tracker=mytracker;" onMouseOver="window.status='http://www.jaspreetchahal.org";
  2. return true" onMouseOut="window.status="">Click here to visit jaspreetchahal.org</a>

As you may already know that because of security reason this window.status does not work the way we wanted to unless you adjust your browser security settings. The text below is taken from w3schools

Note: The status property does not work in the default configuration of IE, Firefox, Chrome, or Safari. To allow scripts to change the text of the status, the user must set the dom.disable_window_status_change preference to false in the about:config screen. (or in Firefox: “Tools – Options – Content -Enable JavaScript / Advanced – Allow scripts to change status bar text”).

Strongly recommended book
Now if you have to tell your visitors to do that, then first thing that will happen is that you will not see them again :) :) I guess.

Now lets do a little trick using jquery

add this jquery function to a global javascript file that is accessible across your website

  1. function hrefTrap(id) {
  2. document.location=$("#"+id).attr('newlink');
  3. return false;
  4. }

Now that we’ve a working function to trap our link click I did this to change my hyper link

  1. <a id="trapclick" onclick="return hrefTrap('trapclick')" href="http://jaspreetchahal.org" newlink="http://jaspreetchahal.org?tracker=1234&#8243;>Click here to visit jaspreetchahal.org</a>

Alright so the above technique works on all browsers with javascript enabled. Now lets answer what if javascript is disabled?

I am sure that you’ve heard noscript tag in HTML

Well yeah, you are thinking right. Below is to get around if javascript is disabled.

  1. // to cater for disabled javascript I will do something like this</pre>
  2. <noscript>
  3. <a href="http://jaspreetchahal.org?tracker=mytracker;" >Click here to visit jaspreetchahal.org</a>
  4. </noscript>
  5. <script type="text/javascript">
  6. document.write("<a id=\"trapclick\" onclick=\"return hrefTrap('trapclick')\" href=\"http://jaspreetchahal.org\"  newlink=\"http://jaspreetchahal.org?tracker=1234\">Click here to visit jaspreetchahal.org</a>");
  7. </script>

I hope this helps.

 

Please leave your comments if you can improve the above code. I know it can be improve to generalize all links on the page but I’ll it to you to work on that.

 

Cheers

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Comments

  1. “global javascript file that is accessible across your website”

    You assume that everyone knows this, but for us dummies, can you please explain?
    Thanks much!

    • sorry about bad wording I guess.
      Anyways what I meant was to have an external javascript file that you can put your common JS functions in and include it in (every page)/(layout file) of your website so that every page will have access to your utility functions.

Speak Your Mind

*

CommentLuv badge