Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Target a PC with CSS/HTML

Featured Replies

I am working on a site that uses a mac font throughout (helvetica neue ultralight) and I'm looking for a way to target any pc with css or html or whatever and redirect to a seperate page or get up a seperate css file.

 

Similar to the target ie code:

 

<!--[if ie]> code <![endif]-->

 

Is this possible?

Not directly, as far as I know. You can only do it by putting the mac font first and then a websafe font so that PCs ignore the mac font and show the websafe font.

 

body { font-family: "helvetica neue ultralight", arial, monospace; line-height: 1.3; color: #335500; background-color: #e9e9e2; font-size: small; }

 

See http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html for browser-safe fonts.

  • Author

yeah ive done that, the site works in IE but i just want it to rediredct to a seperate page.

easily done. The following will redirect all i.e users to a page of your choosing.

 

<!--[if IE]>
<meta http-equiv="refresh" content="0; url=/yourpage.html" />
<script type="text/javascript">
/* <![CDATA[ */
window.top.location = '/yourpage.html';
/* ]]> */
</script>
<![endif]-->

 

This is mega overkill for a font issue, I agree with wickham about font stacks. The above would be useful if you didn't want to support ie6 and wanted to redirect them to a page to download firefox or something.

  • Author

yes, i already have code that redirects IE users, i want to target pc users though, and redirect to a completely different page

Oh I see.

The short answer is no, this can not be done with (x)html/css. Need javascript for that.

  • Author

ok i found this:

 

// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors 
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

 

this will detect and display the OS, how would i alter it so that, instead of displaying the os name, it redirects and result other than 'MacOS' to a seperate page?

Well done; however my javascript is extremely limited, but in the document.write you may be able to write code to redirect (Note, I read somewhere that document.write is out of date javascript, but I don't know what the modern script is and document.write still works).

 

<meta http-equiv="refresh" content="0; url=page2.html"/>

 

is redirect code that normally goes in the head section to redirect to another url

 

so try with trial and error to put that in a document.write; when the browser reaches the meta refresh it may process it instead of displaying it as text. However, I'm sure there's a substitute for document.write to tell a browser to action the code. My advice would be to have only the Windows option if that is what you are trying to target.

 

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";

document.write('<meta http-equiv="refresh" content="0; url=page2.html"/>');

 

That's just a guess, I've no idea if it works. You may have to put in \ before every " in the meta refresh which is required for PHP to disable the " which carries instructions but may not be required for javascript.

 

Good luck. You might get a proper answer on the Javascript board.

  • Author

hmm, when i use that code it seems to just process the

 

<meta http-equiv="refresh" content="0; url=page2.html"/>

 

part and redirects my mac to the alternate page.

 

my javascript is almost certainly worse than your so i cant even really do trial and error stuff, i need it spelled out for me.

 

thanks for the help though! feel like im getting there.

I'm confused about this sequence

!=-1

 

where ! means NOT and the -1 means true or false, but 0 is usually false and 1 is true, so I would expect the code to be

=1 so that if true, it processes the document.write; at least that would happen in PHP.

Instead of using the appVersion property, use the platform property and just use window.location to redirect.

For non macs:

<script type="text/javascript">
if (navigator.platform.indexOf("Mac") == -1) {
window.location = 'otherpage.html';
}
</script>

As for the '-1', that is returned by the indexOf method when no match is found.

 

hth :)

Haha, that's funny!

 

All that hard work, finally paid off! :mf_rudolph:

So your closing your site down to all pc users over a font? o.0

  • Author

nahh just to annoy people who want websites to be available to everyone.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.