简体   繁体   中英

PHP/JavaScript How to combine 2 page in one

I need a reference on how to make 2 pages become one.

Originally i have 2 php pages. View.php and comment.php

The view.php will have a link to call comment.php. When click the 'comment' link, it will open comment.php like pop up. After fill in the comment, and click send, it will closed and return the view.php.

The problem is, Instead of popup i want it hide until i click it. I dont know what is the exact term to call this process. I know it got something to do with javascript, using id, onclick function and similar to frame function. Because i dont know what it call, it hard for me to research. So anyone please tell me what it called or gimme any references or example solution on how to do it.

thank you very much

UPDATED:

dear all..

found this code in internet. Like RageZ said..it uses css and javascript to show and hide img. how to use for others?

do i need to convert my comment.php into a function and put in view.php n use the id for that function. is it possible?

<html>
<head>
<script>
function changeme(id, action) {
       if (action=="hide") {
            document.getElementById(id).style.display = "none";
       } else {
            document.getElementById(id).style.display = "block";
       }
}
</script>

</head>
<body>
<img id="myIMG" style="display: none;" src="question.php.html"width="100" height="100" />
<span onclick="changeme('myIMG', 'show');" style="color: blue; text-decoration: underline; cursor: pointer;">Show the image</span>
<span onclick="changeme('myIMG', 'hide');" style="color: blue; text-decoration: underline; cursor: pointer;">Hide the image</span>
</body>
</html>

I think what your looking for is something like Greybox ?

It opens a new pag ontop of the page, instead of opening a popup, you best check out the examples, they will be way more clear than anything I can say here.

You can do the described process for example with the following:

view.php

<script language="JavaScript">

function openComment(id) // Open comment.php in a new window and send the id of the thing you want to comment
{
    window.open('comment.php?id='+id, '_blank');
}

</script>

<a href="#" onClick="openComment(1)">Comment</a>

comment.php

<?php
    if ( isset($_POST['msg']) && intval($_POST['id']) > 0 ) // If a comment is sent and the id is a number > 0
    {
        /* Write your message to db */
?>
<!-- Reload the underlying window and close the popup -->
<script language="JavaScript">
window.parent.reload();
window.close();
</script>
<?php
    }
    else // Show the Form to post a comment
    {
?>
<form name="comment" action="comment.php" method="POST">
<input type="hidden" name="id" value="<?php echo $_GET['id'] ?>" />
<input type="text" name="msg" value="Input your comment here" />
<input type="submit" value="Submit" />
</form>
<?php } ?>

you can use Ajax/DHTML to make the popup and post the data to the server in the same page.

I think you would need a framework to do that quick there is a lot of javascript framework around:

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