0

I tried googling how to do this but I'm not exactly sure what to call it. Basically there are a few pieces of javascript and html that I want to use across all my pages. Instead of adding these pieces of code to every single page, is there a way to add them all into one file and then use to access them? Also, if anyone has a good source to read up on this I would appreciate a link.

What I want in my sheet are my js for context menu functions:

function ShowMenu(control, e, id) {
   var posx = e.clientX + 'px';
   var posy = e.clientY + 'px';
   var a = document.getElementById(control);

   a.style.position = 'absolute';
   a.style.display = 'inline';
   a.style.left = posx;
   a.style.top = posy;
   var jqContext = '#' + control;

   var view = document.getElementById("viewId");
   view.href = "Chat.aspx?RecID=" + id; //Construct your URL based on parameter

  }
  function HideMenu(control) {
   document.getElementById(control).style.display = 'none';
  }

My context menu:

<div style="display:none; "   id="contextMenu">
        <table  border="0" cellpadding="0" cellspacing="0" 
            style="border: thin solid #808080; cursor: default;" width="100px" 
            bgcolor="White">
            <tr>
                <td >
                    <a href="#" id="viewId"> View</a>
                    </td>
            </tr>
            <tr>
                <td >
                  <a href="#"  id="editId">Edit</a>
                </td>
            </tr>
        </table>
    </div>

And possibly the menu bar I have on every single page:

        <!-- NAVBAR
    =================== -->
    <div class="navbar-wrapper">
      <!-- Wrap the .navbar in .container to center it within the absolutely positioned parent. -->
      <div class="container">

        <div class="navbar navbar-inverse">
          <div class="navbar-inner">
            <!-- Responsive Navbar Part 1: Button for triggering responsive navbar (not covered in tutorial). Include responsive CSS to utilize. -->
            <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="brand" href="#">Brand</a>
            <!-- Responsive Navbar Part 2: Place all navbar contents you want collapsed withing .navbar-collapse.collapse. -->
            <div class="nav-collapse collapse">
              <ul class="nav">
                <li class="active"><a href="#">Home</a></li>
                <%try
     { %>
     <% if ((bool)Session["userIsAuthenticated"] == false) %>
     <% {%>
      <li><a href="LogIn.aspx"">Log in</a></li>
     <% } %>
     <%else %>
     <%{ %>
      <li><a href="InitializePage.aspx">Log Out</a></li>
      <li class="dropdown">
       <a href="#" class="dropdown-toggle" data-toggle="dropdown">Art</a>
       <ul class="dropdown-menu">
        <li><a href="UploadArt.aspx">Upload Art</a></li>
        <li><a href="SearchForArt.aspx">Search For Art</a></li>
       </ul>
      </li>
      <li><a href="MeetPeople.aspx">Meet People!</a></li>
     <%} %>
    <%} %>
    <%catch { Response.Redirect("~/InitializePage.aspx"); } %>

    <li><a href="Register.aspx">Register</a></li>
    <%try
    {
     if (((bool)Session["userIsAuthenticated"]) == true)
     {%>
      <li><a href="UserStats.aspx">User Information</a></li>
     <%}
    }
    catch
    {
     Response.Redirect("~/InitializePage.aspx");
    }%>
    <li><a href="">Donate!</a></li>
              </ul>
            </div><!--/.nav-collapse -->
          </div><!-- /.navbar-inner -->
        </div><!-- /.navbar -->

      </div> <!-- /.container -->
    </div><!-- /.navbar-wrapper -->

Thanks

Articulate
  • 13
  • 3
  • I believe you're looking for something like [this](https://www.w3schools.com/tags/att_script_src.asp) or like [this](https://stackoverflow.com/questions/11498068/how-to-use-external-js-files) – A. W. Aug 28 '17 at 22:21
  • @A.Williams Yes I can link the javascript in like that, but what about the context menu and the menu bar? – Articulate Aug 28 '17 at 22:25
  • See if [this](https://stackoverflow.com/questions/16132341/best-practice-to-create-a-template-in-html) helps at all – A. W. Aug 28 '17 at 22:28
  • It looks like you're doing this in ASP.NET? If so, have a look at Master pages and Components if you're in regular web forms as it appears, or Layouts and Partial Views if you're using the MVC framework – Paul Aug 28 '17 at 23:59
  • I was going to look into that, but as of now I'm not using MVC, I'm just using ASP.NET Forms. – Articulate Aug 29 '17 at 00:41

0 Answers0