Os Detection

By Gabrys Gabrys

Description

This snippet allows creating custom software download list, that links to files depending on the OS running by visitor.

Code

This is basically done by having a code block with custom HTML inside:

use [[code type="HTML"]]

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>Download product for you OS!</title><metahttp-equiv="content-type"content="text/html; charset=utf-8"/><scripttype="text/javascript"src="http://jquery.com/src/jquery-latest.min.js"></script><scripttype="text/javascript"src="http://davecardwell.co.uk/javascript/jquery/plugins/jquery-browserdetect/jqbrowser-uncompressed.js"></script><scripttype="text/javascript">
 $(function() {
 if ($.browser.win()) {
 $("#mac, #linux").hide();
 } else if ($.browser.mac()) {
 $("#linux, #win").hide();
 } else if ($.browser.linux()) {
 $("#mac, #win").hide();
 } else {
 $("#all").hide();
 }
 $("#all a").click(function() {
 $("#mac, #linux, #win").show();
 $("#all").hide();
 });
 });
 </script></head><body><h1>Download</h1><divid="win"><ahref="win.exe">Windows</a></div><divid="mac"><ahref="mac.dmg">Mac OS</a></div><divid="linux"><ahref="linux.tar.gz">Linux</a></div><divid="all"><ahref="javascript:;">Show all systems</a></div></body></html>

You can wrap it in some div that does not render, or hide it somewhere off the screen.

Then you need to iframe this with:

[[iframe http://snippets.wikidot.com/code:os-detection/code ]]

The iframe can be then style to match your site.

Optionally instead embedding the iframe source in the wiki page you can upload the HTML as a file attached to the wiki page and then use the file URL in the iframe destination.

In action

[フレーム]


Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by Gabrys


Rate this solution

If you think this solution is useful — rate it up!

rating: +4
Berdusk Berdusk 27 Jun 2010 19:39

This is all a bit over my head, so please pardon my ignorance, but…

Is there a way to use something like this for a page redirect in the iframe? And is there a way to differentiate between OS versions?

For example, if a visitor is running Windows 7, the iframe page might default to index.htm.
But if they're running Windows XP, it redirects to index2.htm.
Or linux (any) it might default to index3.htm.

And so on…

Any takers? (o.O)

by Berdusk Berdusk , 27 Jun 2010 19:39
Pastword input possible?
Helmut_pdorf Helmut_pdorf 17 Feb 2009 17:37

I have a question to ask for a simple password ( or more for decisions into some different target links) on the community forum:
http://community.wikidot.com/forum/t-131175/if-then-statements#post-387757

Is it possible to change to create a little html / js code ( I am not html or better .js proofed) to ask for a little text and than "show" this only one allowed link ( div) and hide all others?

Hope my question is clear?


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

Last edited on 17 Feb 2009 17:38 by Helmut_pdorf
by Helmut_pdorf Helmut_pdorf , 17 Feb 2009 17:37
I would
Helmut_pdorf Helmut_pdorf 11 Feb 2009 15:22

in the Download section insert my Wikidot pages - URL's with the separated OS-dependetnt Doanload files….

And a click on the Operating system would "surfe" to the OS-dependent Download pages…


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

by Helmut_pdorf Helmut_pdorf , 11 Feb 2009 15:22
Confusing...
pieterh pieterh 11 Feb 2009 14:36

This looks really useful but it seems to use undocumented features - I don't see anything in the iframe section about showing code blocks.

Optionally instead embedding the iframe source in the wiki page you can upload the HTML as a file attached to the wiki page and then use the file URL in the iframe destination.

So this is another iframe feature I'm not aware of. I'm reading http://www.wikidot.com/doc:wiki-syntax#toc44. Is there more documentation on iframe?

Lastly, the example in fact shows Windows, Mac OS, and Linux… rather than one choice. Maybe it does not work on this box.

Sorry if I missed something with putting arbitrary HTML content in iframes, I thought this was insecure and thus not allowed.

by pieterh pieterh , 11 Feb 2009 14:36
Re: Confusing...
Helmut_pdorf Helmut_pdorf 11 Feb 2009 15:05

As I understand I can see which OS I run on the machine of the browsing session…( no idea if this can be important later)

And about the html-usages in iframe:
"Iframe" in conjunction with html scripting is a powerful tool now!

Have a look on
http://community.wikidot.com/howto:use-html-scripting or
http://snippets.wikidot.com/code:use-any-html-code-on-a-page ( looks like the same )
http://community.wikidot.com/blog:html-within-wikidot-type-2


Service is my success. My webtips:www.blender.org (Open source), Wikidot-Handbook.

Sie können fragen und mitwirken in der deutschsprachigen » User-Gemeinschaft für WikidotNutzer oder
im deutschen » Wikidot Handbuch ?

Last edited on 11 Feb 2009 15:08 by Helmut_pdorf
by Helmut_pdorf Helmut_pdorf , 11 Feb 2009 15:05
Re: Confusing...
Gabrys Gabrys 15 Feb 2009 10:48

Lastly, the example in fact shows Windows, Mac OS, and Linux... rather than one choice. Maybe it does not work on this box.

Try now. It has been somewhat wrong for some time. Also notice, that the script nicely degrades, i.e. shows all systems if:

  • JavaScript is disabled
  • OS is not matched by script
  • user clicks "Show all systems"

Sorry if I missed something with putting arbitrary HTML content in iframes, I thought this was insecure and thus not allowed.

The arbitrary HTML is now run from *.wdfiles.com domains and as as so, cannot access any content or page attributes (or run JavaScript code) from *.wikidot.com domains.


Piotr Gabryjeluk
visit my blog

by Gabrys Gabrys , 15 Feb 2009 10:48
Re: Confusing...
pieterh pieterh 15 Feb 2009 12:10

@Piotr: it works now. I'll have to explore this iframe+HTML later, it looks really useful.

Thanks! This is going to be very useful.

by pieterh pieterh , 15 Feb 2009 12:10
Re: Confusing...
Gabrys Gabrys 15 Feb 2009 12:34

You're welcome.


Piotr Gabryjeluk
visit my blog

by Gabrys Gabrys , 15 Feb 2009 12:34
page revision: 6, last edited: 16 Feb 2012 01:27
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).

AltStyle によって変換されたページ (->オリジナル) /