Pregunta

I want to include in my web page another web page. I know how to do that.

<html>
<head>
<br>
<some links to external scripts...><br>
<br>
</head><br>
<body onload='$("#divkat").load("page1.php");'><br>
<div><br>
<br>
<br>
<div class="sidebar"><br>
              <h3>category :</h3><br>
         <a onclick='$("#divkat").load("page1.php");'>page1</a><br>
         <a onclick='$("#divkat").load("page2.php");'>page2</a><br>
         <a onclick='$("#divkat").load("page3.php");'>page3</a><br>
             <a onclick='$("#divkat").load("page2.php");'>page4</a><br>
           </div><br>
<br>
<br>
<div id="divkat"><br>< /div><br>
<  ! - - < ?php include( 'page1.php' ); ?>    - - ><br>
             < /div><br>
            < /div>
<br>
<br>
<br>
</body><br>
</html>

it's working fine.

the problem is that the "page1.php" contain a few shadowbox (lightbox). like this :

 <br>
< /div><br>
< div style="height:180px;width:180px;float:left;margin-top:15px;margin-left:15px;"><br>
< a href="img/panorama-split.jpg" rel="shadowbox; height=500; width=960"><br>< img src="img/tumb-kastel.jpg" alt="Klematis" width="180" height="180" />< /a><br>
< div>

the main page won't run the JS. If I open the "pag1.php" it work normally.

I want to make a web gallery (main page containing categories) when I click on a category, php function include a page containing the items which open in a shadowbox. One solution is to have many pages as categories, but is not piratical. To add a new category you must edit all of them. Someday maybe I'll program a admin interface for easy adding new category, pictures, and other media with links and thumbnails. Ofcorse with possibility to delete and backup.

Thank you

¿Fue útil?

Solución

One problem you have here is that you are using HTML comments:

<  ! - -

This means that when PHP includes the HTML in page1.php it will actually be commented out. Try just:

< ?php include( 'page1.php' ); ?><br/>

Instead.

As to the rest, maybe we can get some clarification. Page1.php contains no JS so how can it run the JS as normal when opening it directly? Maybe you can explain what doesn't work normally?

Edit

I have a feeling you are referring to the body onLoad within your question. If so I have always found JQuery to be a bit weird when put into the HTML directly. Instead you can try and run your JQuery after the DOM itself has loaded by putting this into your head tag:

<script type="text/javascript">
    $(function(){
        $("#divkat").load("page1.php");
    });
</script>

And replace the body tag with:

<body>

Also for the hyperlinks you might wanna look into using JQuery events using the function on(): http://api.jquery.com/on/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top