Search code examples
javascripthtmldata-transfer

How can I change html code of a page from another page?


At page index.htm, I have this list:

<ul id="topic">
<li id="1">Thing1.</li>
<li id="2">Thing2.</li>
</ul>

I'd like to add and remove li itens from other page (painel.htm):

At page painel.htm I'll have a input-text where the user writes the li container (thing1, 2, 3...) and a button to add or remove (currently in javascript-jquery).

I'd like to know the process that gives the information from the painel to the index.

At last case, I can make these pages asp using c#.


Solution

  • Generate navs through js!
    
    <script>
    /* 2 pages nav or define your own */
    var pages = [ [ {id:'1',title:'Thing1'} , {id:'2',title:'Thing2'} ] , 
                  [ {id:'3',title:'Thing3'} , {id:'4',title:'Thing4'} ]
                ];
    
    /* set current page through asp.net or php like currentPage =0 for index.html and currentPage =1 for painel.htm */
    
    var currentPage = 0;
    function renderNavs()
    {
         var data = pages[currentPage];
         for(var i=0; i<data.length ; i++)
         {
              $('#topic').append('<li id="'+data[i].id+'">' + data[i].title + '</li>');
    ');
         }
    }
    
    $('#topic').empty();
    renderNavs();
    </script>