PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label head. Show all posts
Showing posts with label head. Show all posts

Monday, July 18, 2022

[FIXED] When do you put Javascript in body, when in head and when use doc.load?

 July 18, 2022     document-body, head, javascript, jquery, location     No comments   

Issue

Possible Duplicate:
Where to place Javascript in a HTML file?
Should I write script in the body or the head of the html?

I've always wondered, mainly because when creating pages I always run into trouble, based on the following thing:

When do you write your javascript

  • In the <head>
  • In the <body>
  • with a $(document).ready()

I could be stupid, but I've had a few times when my JavaScript (/jQuery) wasn't executed because of the wrong place or yes or no doc.ready() command. So I'm really wondering so.

Same goes for jQuery and 'var' command


Solution

$(document).ready() simply ensures that all DOM elements are loaded before your javascript is loaded.

When it doesn't matter

Without waiting for this event to fire, you may end up manipulating DOM elements or styles that are yet to exist on the page. the DOM ready event also allows you more flexibility to run scripts on different parts of the page. For example:

<div id="map"></div>
<script type="text/javascript">document.getElementById('map').style.opacity = 0;</script>

will run because the map div has been loaded before the script runs. In fact, you can get some pretty good performance improvements by placing your scripts at the bottom of the page.

When it does matter

However, if you are loading your scripts in the <head> element, most of your DOM has not loaded. This example will not work:

<script type="text/javascript">document.getElementById('map').style.opacity = 0;</script>
<div id="map"></div>

will not, since the map div has not been loaded.

A safe solution

You can avoid this by simply wait until the entire DOM has loaded:

<script type="text/javascript">$(document).ready(function () { 
    document.getElementById('map').style.opacity = 0;
});
</script>
<div id="map"></div>

There are plenty of articles that explain this, as well as the jQuery documentation itself.



Answered By - Kyle
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why does liquid {%SEO%} tag not get integrated into head? instead it shows in body

 July 18, 2022     document-body, head, jekyll, liquid     No comments   

Issue

For some unknown reason any LIQUID syntax used inside <head> ends up in the <body>

What I have done?

1) I cloned a template and build my own layout with JEKYLL static site generator.
2) I installed all gems (check gemlist: 'jekyll-seo-tag' 'liquid 4.0')
3) I configured config.yml
4) I added {%SEO%} to <head>

Minimal

<head>

  <meta charset="utf-8">
  <meta name="author" content="Gino Ludikhuyze">
  <meta name="description" content="{% if page.excerpt %}{{ page.excerpt | strip_html | strip_newlines | truncate: 160 }}{% else %}{{ site.description }}{% endif %}">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- Title -->

  <title>title</title>

  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="css/responsive.css">
  <script src="js/vendor/modernizr-2.8.3.min.js"></script>

  {% seo %}

</head>

What is happening?

If I render the website, online or local host, It shows a white GAP at the top. If I inspect it. It shows my liquid TAG in the body.

What I expect to happen?

That liquid should work in cohesion with jekyll.

Link to repo: https://github.com/bomengeduld/reno
Link to website: https://bomengeduld.github.io/reno/


Solution

Your index.html should start with (empty frontmatter):

---
---

Otherwise the Liquid will not get rendered. That is all!



Answered By - Mr. Hugo
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, January 25, 2022

[FIXED] Using Meta Description in the right place CakePHP 3

 January 25, 2022     cakephp, cakephp-3.x, head, metadata, smarty     No comments   

Issue

I am trying to use meta tags and description in cakephp 3. It is working so far, but I am facing the problem that I can´t put it in the of my page, because my .ctp files are rendered in my default.ctp

So for example I have my menu, footer etc. in my default.ctp and my page for the faq is in the faq.ctp How can I push those

<?php
echo $this->Html->meta('description','enter any meta description here');
?>

metadescription in the head tag? Do I need a template language like smarty and use blocks?


Solution

In layout:

<?php
echo $this->Html->meta('description',$description);
?

in your faq.ctp or faq() method:

<?php
$this->set('description','enter any meta description here');
?


Answered By - Salines
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing