Hey everyone, I am having a problem with a website I'm trying to build; basically I have a class that I call from my header file that loads all of the link and script tags. The link tags show up across all browsers, but the script tags only show up in safari and chrome, they do no show up in firefox or IE.
<script type='text/javascript' src='...'>
now I have tried removing the "<" at the front of the tag just to see what happens, and it will show up as plain text then, but as soon as I put the "<" back it is again MIA.
So here is what's going on in the php. My header.php file calls the cms object function, located in cms.php, and those functions call other functions in my system.php file.
Now, again the link tags work w/out a hitch and I call them the exact same way ... it is just the dumb script tags. When I call the load_js("config"); function in my header.php it will load multiple tags as well. If it was just 1 tag I would put the script tags in the html rather than in the php, but I don't think I can do that when I'm producing multiple tags.
Any help would be great! Thanks in advance as well!
header.php
<?php echo $this->load_css("config"); ?>
<?php echo $this->load_js("config"); ?>
cms.php
function load_js($name){
// ...
return header_script($name.".js");
// ...
}
function load_css($name){
// ...
return header_link($name.".css");
// ...
}
system.php
function header_script(){
// 0 = src
$num = func_num_args();
if($num == 0){
return;// if no arguments, can't successfully build header_script.
}
if($num == 1){
return "<script type='application/javascript' src='".func_get_arg(0)."'><开发者_如何转开发/script>\n";
}
}
function header_link(){
$num = func_num_args();
// 0 = rel
// 1 = type
// 2 = href
if($num < 3){
return; // can't successfully build link.
}
if($num == 3){
return "<link rel='".func_get_arg(0)."' type ='".func_get_arg(1)."' href='".func_get_arg(2)."' />\n";
}
}
Firstly, application/javascript
is not recognized by some browsers. You should change that to text/javascript
Secondly, as mentioned in comments (Justin Johnson), you should use parameters in your function definition with default values:
function header_script($name = '')
{
if ($name != '') {
return '<script type="text/javascript" src="'.$name.'"</script>';
}
}
精彩评论