Question

I'm trying to load a portion of the page using jquery .load(), the link is a unique .php page with manually scripted jquery code, but I face two problems:

  1. Previously loaded jquery plugins will no longer works and I will need to reloaded them within a head tag and I need to add a head tag to do so.....

  2. My .php code will generate an error since the .php file wasn't meant to be loaded separately but as a whole, like index.php, but I don't want the whole page to get refresh though...

Is it ok to load a new Doctype within a html div or is there a better practice, like so:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Default</title>
<script><!--jquery library here--></script>
<script><!--jquery slidwshow plugin--></script>
</head>

<body>
<div class="header">header template here</div>
<div class="content">

    <!--dynamic html with doctype-->
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Default</title>
    </head>
        <body>
            <div>dynamic content loaded here</div>
        </body>
    </html>
    <!--end dynamic html with doctype-->

</div>
<div class="footer">footer template footer</div>
</body>
</html>

Thanks for the help!

Was it helpful?

Solution

No, the DOCTYPE can only be declared at the top of the page. (And the very first non-white space characters)

To make life ever-so-interesting, iframes are handled differently by different browsers.

Some version of IE will allow an iframe to set its own DOCTYPE, others inherit from the parent frame.

I can't recall which versions do which, but I do recall running into this issue before.

EDIT

AH, found a discussion here -- seems to be IE9 where the iframe inherits from the parent:

DOCTYPE, iFrames, HTML5 - together

OTHER TIPS

If your website is modular you would define the doctype in the module. Have the page load check the modules doctype and then use a switch statement in your header.

   global $somemodulename;

   if (($somemodulename == Music)    
   { 
     if(@file_exists(module/somemodulename/includes/doctype.php'))
     {                                                                                                   
       require_once(module/somemodulename/includes/doctype.php');
     }
   }

Parsing the module Sub Folder on load for doctype.php above can be done a lot different I am just trying to explain the concept.

   switch ($doctype) 
   {
     case 'HTML':
     $output =  '<!DOCTYPE html>'."\n";
     $output .= '<meta charset="UTF-8">'."\n";
     define('DOCTYPE', 'HTML');
     break; 
     case 'strict':
     $output =  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
     define('DOCTYPE', 'strict');
     break;
     case 'transitional':
     $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
     define('DOCTYPE', 'transitional');
     break;
     case 'frameset':
     $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
     define('DOCTYPE', 'frameset');
     break;
     case 'math':
     $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd">';
     define('DOCTYPE', 'math');
     break;
     case 'xhtml11':
     $output =  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
     define('DOCTYPE', 'xhtml11');
     break;
     case 'default':
     $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
     define('DOCTYPE', 'transitional');
     break;
   }

I already use this in PHP-Nuke Titanium and it works fine. My code is a little more elaborate but you get the gist of what I am saying. I use the doctype switch to test browser code. I took it from my browser workbench. This is used to make old modules written by other people compatible with PHP-Nuke Titanium.

You can have your header so that it is called separate if your website is not modular. That way each page load sets the modulename or pagename and the header invokes the switch on the fly.

You can embed PHP code into HTML and Vice Versa :)

This concept can be used to do exactly what you asked. I know this post was old but we all need to share our ideas. Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top