WN

WN (https://www.wn.se/forum/index.php)
-   Klientsidans teknologier, design och grafik (https://www.wn.se/forum/forumdisplay.php?f=12)
-   -   If IE -script i <head> SMF (https://www.wn.se/forum/showthread.php?t=33799)

pitbull 2008-12-07 20:40

Någon PHP-Guru som kan förklara för mig hur jag kan lägga in denna kodsnutt i <head> ?

Citat:

<!--[if IE]>
<script>
window.onload = function()
{
if (!window.location.search)
{
setTimeout("window.location+='?';", .1000);
}

}

</script>

<![endif]-->

Det gäller ett SMF-forum / index.template
<head>-kod:
Citat:

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
<meta name="robots" content="noindex" />', '
<meta name="keywords" content="" />
<meta http-equiv="content-language" content="sv" />
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var smf_theme_url = "', $settings['theme_url'], '";
var smf_images_url = "', $settings['images_url'], '";
var smf_scripturl = "', $scripturl, '";
var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
var smf_charset = "', $context['character_set'], '";
// ]]></script>


<title>', $context['page_title'], '</title>';

// The ?fin11 part of this link is just here to make sure browsers don't cache it wrongly.
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?fin11" />
<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/print.css?fin11" media="print" />';

/* Internet Explorer 4/5 and Opera 6 just don't do font sizes properly. (they are big...)
Thus, in Internet Explorer 4, 5, and Opera 6 this will show fonts one size smaller than usual.
Note that this is affected by whether IE 6 is in standards compliance mode.. if not, it will also be big.
Standards compliance mode happens when you use xhtml... */
if ($context['browser']['needs_size_fix'])
echo '
<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/fonts-compat.css" />';

// Show all the relative links, such as help, search, contents, and the like.
echo '
<link rel="help" href="', $scripturl, '?action=help" target="_blank" />
<link rel="search" href="' . $scripturl . '?action=search" />
<link rel="contents" href="', $scripturl, '" />';

// If RSS feeds are enabled, advertise the presence of one.
if (!empty($modSettings['xmlnews_enable']))
echo '
<link rel="alternate" type="application/rss+xml" title="', $context['forum_name'], ' - RSS" href="', $scripturl, '?type=rss;action=.xml" />';

// If we're viewing a topic, these should be the previous and next topics, respectively.
if (!empty($context['current_topic']))
echo '
<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';

// If we're in a board, or a topic for that matter, the index will be the board's index.
if (!empty($context['current_board']))
echo '
<link rel="index" href="' . $scripturl . '?board=' . $context['current_board'] . '.0" />';

// We'll have to use the cookie to remember the header...
if ($context['user']['is_guest'])
{
$options['collapse_header'] = !empty($_COOKIE['upshrink']);
$options['collapse_header_ic'] = !empty($_COOKIE['upshrinkIC']);
}

// Output any remaining HTML headers. (from mods, maybe?)
echo $context['html_headers'], '

<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var current_header = ', empty($options['collapse_header']) ? 'false' : 'true', ';

function shrinkHeader(mode)
{';

// Guests don't have theme options!!
if ($context['user']['is_guest'])
echo '
document.cookie = "upshrink=" + (mode ? 1 : 0);';
else
echo '
smf_setThemeOption("collapse_header", mode ? 1 : 0, null, "', $context['session_id'], '");';

echo '
document.getElementById("upshrink").src = smf_images_url + (mode ? "/upshrink2.gif" : "/upshrink.gif");

document.getElementById("upshrinkHeader").style.di splay = mode ? "none" : "";
document.getElementById("upshrinkHeader2").style.d isplay = mode ? "none" : "";

current_header = mode;
}
// ]]></script>';

// the routine for the info center upshrink
echo '
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var current_header_ic = ', empty($options['collapse_header_ic']) ? 'false' : 'true', ';

function shrinkHeaderIC(mode)
{';

if ($context['user']['is_guest'])
echo '
document.cookie = "upshrinkIC=" + (mode ? 1 : 0);';
else
echo '
smf_setThemeOption("collapse_header_ic", mode ? 1 : 0, null, "', $context['session_id'], '");';

echo '
document.getElementById("upshrink_ic").src = smf_images_url + (mode ? "/expand.gif" : "/collapse.gif");

document.getElementById("upshrinkHeaderIC").style. display = mode ? "none" : "";

current_header_ic = mode;
}
// ]]></script>




</head>


Björn 2008-12-07 22:14

vad ska du med php till? det där är ju conditional css och javascript. det är väl bara att lägga in det direkt innan </head>...

för att komma ur php om det är så.. så gör såhär

?>
din kod här
<?

crazzy 2008-12-07 22:44

Skriv aldrig <? ... ?>

Det är riktigt dålig kod tycker jag. Det är ingen riktig start-tag. Använd <?php ... ?>

pitbull 2008-12-07 23:22

Njaää, att lägga in direkt kodsnutten direkt i <head> som i vanlig XHTML ger parsing error. Har provat ett flertal varianter utan framgång. Google ger ingenting som man blir klokare av heller...

Björn 2008-12-08 00:15

Citat:

Originally posted by crazzy@Dec 7 2008, 23:44
Skriv aldrig <? ... ?>

Det är riktigt dålig kod tycker jag. Det är ingen riktig start-tag. Använd <?php ... ?>

Sålänge du har kontroll över webbservern, och php.ini , eller iaf short_open_tag påslaget (det är det oftast) så är det funktionsmässigt indentiskt, inte dålig kod, bara ett annat sätt att skriva det på, på gott och inte så värst mkt ont. imo.

Det är dock ot.

pitbull vad säger parsern?

Alex 2008-12-08 00:25

Escapea ' så löser det sig. Sedan kan du klistra in koden precis innan </head>.

Kod:

<!--[if IE]>
<script>
window.onload = function()
{
if (!window.location.search)
{
setTimeout("window.location+=\'?\';", .1000);
}

}

</script>

<![endif]-->

Kod:

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
<meta name="robots" content="noindex" />', '
<meta name="keywords" content="" />
<meta http-equiv="content-language" content="sv" />
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
 var smf_theme_url = "', $settings['theme_url'], '";
 var smf_images_url = "', $settings['images_url'], '";
 var smf_scripturl = "', $scripturl, '";
 var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
 var smf_charset = "', $context['character_set'], '";
// ]]></script>


<title>', $context['page_title'], '</title>';

// The ?fin11 part of this link is just here to make sure browsers don't cache it wrongly.
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?fin11" />
<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/print.css?fin11" media="print" />';

/* Internet Explorer 4/5 and Opera 6 just don't do font sizes properly. (they are big...)
 Thus, in Internet Explorer 4, 5, and Opera 6 this will show fonts one size smaller than usual.
 Note that this is affected by whether IE 6 is in standards compliance mode.. if not, it will also be big.
 Standards compliance mode happens when you use xhtml... */
if ($context['browser']['needs_size_fix'])
 echo '
<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/fonts-compat.css" />';

// Show all the relative links, such as help, search, contents, and the like.
echo '
<link rel="help" href="', $scripturl, '?action=help" target="_blank" />
<link rel="search" href="' . $scripturl . '?action=search" />
<link rel="contents" href="', $scripturl, '" />';

// If RSS feeds are enabled, advertise the presence of one.
if (!empty($modSettings['xmlnews_enable']))
 echo '
<link rel="alternate" type="application/rss+xml" title="', $context['forum_name'], ' - RSS" href="', $scripturl, '?type=rss;action=.xml" />';

// If we're viewing a topic, these should be the previous and next topics, respectively.
if (!empty($context['current_topic']))
 echo '
<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';

// If we're in a board, or a topic for that matter, the index will be the board's index.
if (!empty($context['current_board']))
 echo '
<link rel="index" href="' . $scripturl . '?board=' . $context['current_board'] . '.0" />';

// We'll have to use the cookie to remember the header...
if ($context['user']['is_guest'])
{
 $options['collapse_header'] = !empty($_COOKIE['upshrink']);
 $options['collapse_header_ic'] = !empty($_COOKIE['upshrinkIC']);
}

// Output any remaining HTML headers. (from mods, maybe?)
echo $context['html_headers'], '

<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
 var current_header = ', empty($options['collapse_header']) ? 'false' : 'true', ';

 function shrinkHeader(mode)
 {';

// Guests don't have theme options!!
if ($context['user']['is_guest'])
 echo '
 document.cookie = "upshrink=" + (mode ? 1 : 0);';
else
 echo '
 smf_setThemeOption("collapse_header", mode ? 1 : 0, null, "', $context['session_id'], '");';

echo '
 document.getElementById("upshrink").src = smf_images_url + (mode ? "/upshrink2.gif" : "/upshrink.gif");

 document.getElementById("upshrinkHeader").style.display = mode ? "none" : "";
 document.getElementById("upshrinkHeader2").style.display = mode ? "none" : "";

 current_header = mode;
 }
// ]]></script>';

// the routine for the info center upshrink
echo '
 <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
 var current_header_ic = ', empty($options['collapse_header_ic']) ? 'false' : 'true', ';

 function shrinkHeaderIC(mode)
 {';

if ($context['user']['is_guest'])
 echo '
  document.cookie = "upshrinkIC=" + (mode ? 1 : 0);';
else
 echo '
  smf_setThemeOption("collapse_header_ic", mode ? 1 : 0, null, "', $context['session_id'], '");';

echo '
  document.getElementById("upshrink_ic").src = smf_images_url + (mode ? "/expand.gif" : "/collapse.gif");

  document.getElementById("upshrinkHeaderIC").style.display = mode ? "none" : "";

  current_header_ic = mode;
 }
 // ]]></script>
 
 
<!-- Ändrat! -->
<!--[if IE]>
<script>
window.onload = function()
{
if (!window.location.search)
{
setTimeout("window.location+=\'?\';", .1000);
}

}

</script>

<![endif]-->
<!-- / Ändrat! -->
 
</head>


pitbull 2008-12-08 00:42

Sitter lite illa till just nu, så jag har ingen tillgång till eftermiddagens felkoder för tillfället.

Citat:

Escapea ' så löser det sig. Sedan kan du klistra in koden precis innan </head>.
Och det innebär på svenska? Jag är okunnig och behöver därför en "dum-i-huvudet-förklaring"-finns det möjlighet till en sådan?

pitbull 2008-12-08 00:58

"Escapea" ger följande:
Citat:

Parse error: syntax error, unexpected ';' in .../Themes/default/index.template.php on line 199

190:
191: }
192:
193: </script>
194:
195: <![endif]-->";
196:
197:
198: </head>

199: <body>';


pitbull 2008-12-08 01:11

Provat
Citat:

echo '
<!--[if IE]>
<script>
window.onload = function()
{
if (!window.location.search)
{
setTimeout("window.location+='?';", .1000);
}

}

</script>

<![endif]-->
';

och dubbelfnuttvarianten
Citat:

echo "<!--[if IE]>
<script>
window.onload = function()
{
if (!window.location.search)
{
setTimeout("window.location+='?';", .1000);
}

}

</script>

<![endif]-->";

Utan framgång...

MMC 2008-12-08 01:33

Citat:


$setTimeout = <<<EOF
<!--[if IE]>
<script>
window.onload = function()
{
if (!window.location.search)
{
setTimeout("window.location+='?';", .1000);
}

}

</script>

<![endif]-->
EOF;

echo $setTimeout;

Tabba inte ut ovanstående så ska det funka prima.

Alex 2008-12-08 01:41

Pitbull, ta koden jag skrev innan, så funkar det. PHP kan inte veta att strängen som visar hela sidan inte slutar vid '?' i ditt javascript. Därför får du escapea dessa tecken. \'?\'.

ett exempel:

<?php
echo "stenar är "gott""; // kommer inte funka.

echo "stenar är \"gott\""; // kommer funka

echo 'stenar är "gott"'; // kommer funka

echo 'stenar är 'gott''; // kommer inte funka

echo 'stenar är \'gott\''; // kommer funka
?>

pitbull 2008-12-08 02:12

Bockar och tackar allra ödmjukast för er hjälp. Alex-lösningen fungerade alldeles utmärkt. MMC-lösningen gav tyvärr parser-error.

Jag har ingen aning om vad som händer, men så länge det fungerar så är jag nöjd.

Detta skript laddar om sidan 1 gång, för att IE ska kunna skala/visa dynamiska/flytande storlekar på vissa bilder. Fungerar alldeles utmärkt i statisk XHTML. Tyvärr fungerade inte detta i SMF även om scriptet kom igång.

Bara att harva vidare...

Tack ännu en gång för er hjälpsamhet! Hoppas tomten kommer till er med en jättesäck full med hårda paket.

/S


Alla tider är GMT +2. Klockan är nu 23:25.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson