Una soluzione basata su document.write rapida sarebbe:
<script type="text/javascript">
if (/facebook\.com/.test(window.top.location.host)) {
document.write('<link rel="stylesheet" type="text/css" href="stylefacebook.css" />');
}
</script>
o utilizzando il dom:
<script type="text/javascript">
if (/facebook\.com/.test(window.top.location.host)) {
var lnk = document.createElement('link');
lnk.type='text/css';
lnk.href='stylefacebook.css';
lnk.rel='stylesheet';
document.getElementsByTagName('head')[0].appendChild(lnk);
}
</script>
O con jQuery:
<script type="text/javascript">
if (/facebook\.com/.test(window.top.location.host)) {
$('head:first').append('<link rel="stylesheet" type="text/css" href="stylefacebook.css" />');
}
</script>
** ': prima' ** davvero? – qwertymk
per ogni evenienza (-: – arnaud576875
Cosa strana, ma sembra che all'interno di un'app per Facebook ("apps.facebook.com/myapp") window.top.location.host restituisca undefined:/ – Joel