简体   繁体   中英

i want to include a external php file into html page using javascript?

<?php
    header("Content-type: text/javascript");
    include("header.php");
?>
<head>

<script type="text/javascript" src="header.php"></script>

</head>

I'm trying to include a PHP (header & footer) file in an HTML file.

The reason it needs to be HTML is this is a content provider that hosts the content and they've put a restriction on the number of characters that can be in the header (as they host it). Any ideas?

You can not include php in a html page, as php generates html but html can not generate php. So you can try ajax method to include php instead on page load try calling a javascript function which will call the php file.

window.location.assign("header.php"); by this method you can add php file but only in php page..not with html.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM