views:

75

answers:

3

Hi All,

I'd like to be able to create a "HTML link" that the user can click on and be taken to an URL (location) specified either in the browser (preferences?) or system environment.

Is this possible? Any suggestions on how to do it please?

For example, it may look something like this (or alternatively it could be a clickable image or even a submit button):

"Click here to go to your preferred news site."

When the user clicks on "here" the browser would go to a location specified not in the HTML but somehow in the browser (preferences?) or some system environment variable (OS specific etc.)

Of course, the user would have to set up this preference or environment variable (or have some local application or better Web page that could set it - when approved by the user).

This is sort of like most OS these days allow you to set "preferred app" for image processing or playing media. I would like to set preferred Web sites for certain tasks.

Thanks for any suggestions. Hopefully with Javascript and modern browsers and perhaps HTML 5 something like this is possible.

Update: I would like the user to be able to set this once for themselves (e.g. in the browser or the OS) and then for this to work on any site they go to that includes the same "abstract link".

So Web site A and web site B could both an "abstract link" to go to the user's preferred news site and when clicked on the browser would go to the site specified in the browser or the OS). So it cannot be site-specific (like a cookie?).

Cheers, Ashley.

A: 

You can store the preferred web site in a cookie. Simple version using the readCookie function from there:

Click <a href="var dest = readCookie('preferred_site'); window.location = dest ? dest : 'http://default.news.site';"&gt;to go to your preferred news site</a>
Matthew Flaschen
Thanks but I want this to work across different sites / applications and be configured once for the user. I believe cookies are site (i.e. domain specific)? Can cookies be global?
MrHatken
+1  A: 

The general process would be something like this: Set a cookie using js. Then create a function that retrieves the cookie and redirects. Then trigger an onclick or an onmousedown even like onmousedown='retriveAndRedirect()'


Check out there resources.



UPDATE: I see what you're trying to do here. In order for your redirection to work from any site, that site has to host your redirection and preference method somehow using js, html, serverside script, etc...

Your other option would be to build a plugin which the user would have to download, that way you wouln'd need any site host your redirection and preference methods for you.

As far as your link retrieval methods go you can either use cookies, or store the links in a database and then call on trigger.

Babiker
Thanks but I want this to work across different sites / applications and be configured once for the user. I believe cookies are site (i.e. domain specific)? Can cookies be global?
MrHatken
@MrHatken, you can retrieve the cookie anywhere, but the HTML page you're in must have the js function and the event handling element must be able to call the function once triggered.
Babiker
@Babiker the function that retrieves the cookie and redirects that is.
Babiker
Ok, if Javascript can retrieve a cookie written by another application (from another domain) that's fine. No problem with each site having the js function, and for those that can't we could provide a plugin.Thanks folks!
MrHatken
A: 

After reading further, it seems cross-domain cookies are possible, but it is somewhat of a hack and sometimes browser-specific (e.g. with Safari).

So I think I may have to discount that solution.

Is it not possible to use Javascript to access local operating system environment variables? Or something similar (a preference in the browser)?

A plugin would also be a hassle for the user ...

Thanks, Ashley.

MrHatken
You definitely can't access environment variables or browser preferences (e.g. Firefox's about:config) in regular website JavaScript.
Matthew Flaschen