How do I create a new .html webpage onclick? [closed]

强颜欢笑 提交于 2019-12-03 09:04:14

You must use AJAX to execute php. Creating new file in php is really simple with file_put_contents().

here is an example:
makePage.html:

    <html>
    <body>
    <button onclick="makePage()">click</button>
    <script src="makePage.js">
    </script>
    </body>
    </html>

makePage.php:

<?php
$content = $_GET["content"];
$file = uniqid() . ".html";
file_put_contents($file, $content);
echo $file;
?>

makePage.js

function makePage(){
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
    if(xmlhttp.readyState==4 && xmlhttp.status==200)
        alert("webpage " + xmlhttp.responseText + " was successfully created!");
    }
    var content = "<html><head><meta charset=\"utf-8\" /> </head><body>new website<script>alert(\"test\")</script></body></html>";
    xmlhttp.open("GET","makePage.php?content=" + content,true);
    xmlhttp.send();
}

hope this will help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!