开发者

How can I get HTML to link to a browser (or system) specified URL?

开发者 https://www.devze.com 2023-01-01 20:23 出处:网络
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.

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.


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.

  • QuircksMode's JavaScript Cookies Reference.

  • W3School's JavaScript Cookies Reference.



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.


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';">to go to your preferred news site</a>
0

精彩评论

暂无评论...
验证码 换一张
取 消