0

I am using the WYSIWYG editor CKEditor which apparently does not get along with Windows Phone 8 at all (it breaks the entire site when kept in the head). I'm not certain if it's an IE issue overall or Win8 specifically, but the site will be accessed via a custom corp app wrapper so suggesting an alternate browser isn't an option. I don't really care about them losing the functionality.

Is there a simple way I can write something like this into the head in PHP?

if(OS == Windows Phone 8){
    //nothing
} else {
    echo "<script src=\"ckeditor/ckeditor.js\"></script>";
}

I'm open to any solution, but PHP is what I'm using in general.

Chaz
  • 787
  • 2
  • 9
  • 16

3 Answers3

3

You can check the user agent in PHP and include the script if it doesn't match Windows Phone 8:

$pattern = "/Windows\sPhone\s8/";
$user_agent = $_SERVER['HTTP_USER_AGENT'];

if(!preg_match($pattern, $user_agent))
{
    echo "<script src=\"ckeditor/ckeditor.js\"></script>";
}
sbeliv01
  • 11,550
  • 2
  • 23
  • 24
2

If it's IEMobie 10 causing the problem you can check for that in the Useragent.

if(stristr($_SERVER['HTTP_USER_AGENT'], 'IEMobile/10.0') === FALSE)
    echo '<script src="ckeditor/ckeditor.js"></script>';

You could even do it in Javascript if you prefer:

if(navigator.userAgent.indexOf('IEMobile/10.0') === -1)
    document.getElementsByTagName('head')[0].innerHTML += '<script src="ckeditor/ckeditor.js"></script>';

You can also use conditional comments:

<![if !IEMobile]> 
<script src="ckeditor/ckeditor.js"></script>
<![endif]>
Jordan Doyle
  • 2,976
  • 4
  • 22
  • 38
0

Since you're using javascript, why not match the user agent using javascript instead of PHP? [Credit]

if !(navigator.userAgent.match(/IEMobile\/10\.0/)) { ...

*On Windows 7 phone you could target the browser using just HTML, but unfortunately Microsoft got rid of that feature with Windows Phone 7.5.

Brandon Lebedev
  • 2,717
  • 6
  • 24
  • 35