How to efficiently maintain a navigation bar? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I was wondering how to efficiently maintain a navigation bar. Based on my understanding right now, we just include the html code for the bar at each individual webpage. However, if I had many webpages I would need copy and rewrite the html code for each page. And if I would want to add or remove links I would need to change and update all of the pages. Is there a more efficient way to do this?

There are a lot of ways we can achieved this but here are the simplest I can think of right now.
1. Using PHP include_once function
You can use php for that. Simply store your navigation in a file called header.php for example, then include_once('header.php'); in your page. Make sure your page have a .php extension instead of .html
2. Using jQuery
If you want to stay with the current language(HTML,CSS,Javascript), you can also use JQuery load function.
$("#header").load('header.html');
It is better to run this after the DOM is ready:
$(document).ready(function() {
$("#header").load('header.html');
}
Somewhere in your code, you should have <div id="header"> for the script to inject the nav in header.html

what they do is that they load the page which is called from the server, besides the navigation bar. like either you can call the page in an iframe or you can run a script that could render the elements besides the navigation bar. That's how they could maintain the navigation bar

Related

How do I get all my pages to be updated automatically when I update a page? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
So, as I was making my website, I started to have many pages. So, I wanna ask today, if ya'll know anyway way how I can make a change to a page of my website, and those changes be apply to my other pages automatically. For example, if I make a change to my nav bar of my website, I don't wanna have to go to every single page and and do it manually, I wanna know if there is a way how I can make a change to the nav bar in one of the web page, and get the other pages get the updates automatically. I would very much appreciates any advice, thank you.
You can just write your navbar code into a separate file and include it wherever you need navbar. This way if you change the main navbar.php file it will reflect in every other page that includes navbar.php

How can I get the same effect on my webpage? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So I've seen a mouse-hover effect on 2 websites so far and I really like it.
This is the effect I'm talking about.
I'd be grateful if somebody can tell me how to get that effect on my webpage.
It only appears under your cursor when you hover over the page.
The site you have linked in the comments uses the HTML canvas element. But You can simply use already existing libraries for that effect.
Examples mentioned in the comments:
http://jnicol.github.io/particleground/
http://github.com/VincentGarreau/particles.js
Simply, Go to the webpage you wanted to Copy it's effects or anything from it
Right click, View page source
If the effect is made by Css, you will find it in stylesheets tab
If it's using jQuery/Js, Search the head for <script> , Read them and copy the effect (assuming that you understand js/jquery
For more simplicity, use Firebug, open it and just point the cursor at the item you want to see it's source.
But, actually
You can find it at github Here
Change what you want.

Add JS page to SilverStripe [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have already made a HTML page named Phaser.html, and use Javascript and the game framework Phaser.
Now i want to show this page in my silverstripe site. But i'm new in this and relly dont know how to do it, i just see php code, but i wanna just put my files in someweree and then linked to the page.
Another thing, When i add from the CMS, this show me a text editor like word. I should write code in there?.
Im using the simple theme. And i have already a structure of my site.
This is the phaser.html and the silverstripe page
I want to put the page on the left in my Silverstripe site.
Without actually seeing your code, this is going to be a shot in the dark, but perhaps try this:
Put your javascript code into a file named phaser.js. You said all of the code was javascript so a .html file shouldn't even been needed at all.
Copy that file into the mysite/javascript
Edit mysite/code/Page.php
Insert Requirements::js('mysite/javscript/phaser.js'); into the init() function so it looks like this:
public function init() {
parent::init();
Requirements::javascript("site/javascript/phaser.js");
}
Refresh the page and the javascript file should be now loaded as it should now be referenced inside the <head> tag.
Once you get that working I'd recommend taking the next step of creating your own Phaser_Page class that extends Page and move the Requirements call to that page and possibly create a custom template for your new page. How to do all that should be covered in the SilverStripe Lessons.

Login/registration button to open php file on same page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
First of all sorry for my English. I'm working on a little website (I'm learning web design and PHP). As you can see in the page index.php, there are three buttons: login, registration (register) and guest. I've three scripts, one for login, one for register and one for guest access to site.
How can I show the script "login.php" or "register.php" or "guest.php", just under the buttons, when I click on the corresponding button?
Here are index.php and css files:
Download
use jQuery http://www.jquery.com makes life soo much easier
$(document).on("click","#login-btn",function(){
$("#div-where-to-load-stuff").load("url/to/login.php");
})
this is very bare bones. there are better ways to do it tho.
http://api.jquery.com/load/
You will have to either use AJAX or an IFRAME to load content asynchronously.
I really like to use the jQuery Forms plugin (in case you are able to use jQuery). Otherwise you have to look into AJAX or iFrame.

Acces DOM from external site with js or jquery [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a php script(example.php), which is using multiple cURL to load 20 pages at the same time.. for example google.com, ebay.com .. It takes 5 seconds to load example.php and its quite a lot so.. I also have a simple html file(index.html) with short loadtime . And what I want is : having a script included in index.html which gets element by id from pages loaded in example.php And why? I want to have a page with fast load time(index.html), which could get elements from sites like google.com, ebay.com, facebook.com (which are actually loaded in example.php on the background) ... Example.php and index.html are on the same domain, so there should be no problem with that..
Accessing content from external websites can't be done easily with Javascript due to the Same Origin Policy. You can however display the entire page in one go by use of an iframe.
You can circumnavigate this with a variety of methods using the server as neatly provided here.

Categories