Szybkie rozwiązanie document.write oparte byłoby:
<script type="text/javascript">
if (/facebook\.com/.test(window.top.location.host)) {
document.write('<link rel="stylesheet" type="text/css" href="stylefacebook.css" />');
}
</script>
lub używając 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>
lub za pomocą 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>
** ': first' ** really? – qwertymk
na wszelki wypadek (-: – arnaud576875
Dziwne, ale wydaje się, że wewnątrz aplikacji Facebook („apps.facebook.com/myapp”) window.top.location.host powraca niezdefiniowanej:/ – Joel