If IE -script i <head> SMF

Visa första olästa
Ämnesverktyg
Visa huvudforum
Visningsalternativ
Oläst 2008-12-07, 21:40 #1
pitbullpitbull är inte uppkopplad
Har WN som tidsfördriv
pitbulls avatar
Reg.datum: Maj 2004
Inlägg: 1 100
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.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>




</head>
pitbull är inte uppkopplad
Oläst 2008-12-07, 23:14 #2
BjörnBjörn är inte uppkopplad
Har WN som tidsfördriv
Reg.datum: Maj 2004
Inlägg: 1 224
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
<?
Björn är inte uppkopplad
Oläst 2008-12-07, 23:44 #3
crazzycrazzy är inte uppkopplad
Har WN som tidsfördriv
crazzys avatar
Reg.datum: Aug 2007
Inlägg: 1 089
Skriv aldrig <? ... ?>

Det är riktigt dålig kod tycker jag. Det är ingen riktig start-tag. Använd <?php ... ?>
crazzy är inte uppkopplad
Oläst 2008-12-08, 00:22 #4
pitbullpitbull är inte uppkopplad
Har WN som tidsfördriv
pitbulls avatar
Reg.datum: Maj 2004
Inlägg: 1 100
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...
pitbull är inte uppkopplad
Oläst 2008-12-08, 01:15 #5
BjörnBjörn är inte uppkopplad
Har WN som tidsfördriv
Reg.datum: Maj 2004
Inlägg: 1 224
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?
Björn är inte uppkopplad
Oläst 2008-12-08, 01:25 #6
AlexAlex är inte uppkopplad
Administratör
Alexs avatar
Reg.datum: Sep 2004
Inlägg: 1 621
Escapea ' så löser det sig. Sedan kan du klistra in koden precis innan </head>.

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

}

</script>

<![endif]--> 


CODE
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>

Alex är inte uppkopplad
Oläst 2008-12-08, 01:42 #7
pitbullpitbull är inte uppkopplad
Har WN som tidsfördriv
pitbulls avatar
Reg.datum: Maj 2004
Inlägg: 1 100
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 är inte uppkopplad
Oläst 2008-12-08, 01:58 #8
pitbullpitbull är inte uppkopplad
Har WN som tidsfördriv
pitbulls avatar
Reg.datum: Maj 2004
Inlägg: 1 100
"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 är inte uppkopplad
Oläst 2008-12-08, 02:11 #9
pitbullpitbull är inte uppkopplad
Har WN som tidsfördriv
pitbulls avatar
Reg.datum: Maj 2004
Inlägg: 1 100
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...
pitbull är inte uppkopplad
Oläst 2008-12-08, 02:33 #10
MMCMMC är inte uppkopplad
Mycket flitig postare
MMCs avatar
Reg.datum: Jan 2008
Inlägg: 560
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.
MMC är inte uppkopplad
Aktiva användare som för närvarande tittar på det här ämnet: 0 (0 medlemmar och 0 gäster)