I want to include a PHP file which is for Loading JavaScript and then remove it completely from page. I found same article here but I don't know how to use it.
Let's see I included PHP like this in top of page.
<?php include 'loader.php';?>
So, how to remove it when page loaded completely?
loader.php is already working singly, I mean after few seconds will be removed loading content, but it doesn't work when I include it to other page. so how to do it?
Thanks
Put your content into div
<div class="js-remove-this"> <?php include 'loader.php';?> </div>
Then listen with JS for page onload event and remove div.js-remove-this
Related
So I have a website, https://coolkids.gq. I want to be able to add a certain line of code to every single HTML file on the website using another HTML, JavaScript or PHP file, but I am not sure how to do this.
How would I be able to write a script to add a line of custom code to every HTML page on my website?
Edit: As pointed out by charlieftl, I should clarify that all files are saved in either the /htdocs folder or in a folder inside of that.
yes you can, just make some folder named include or whatever and create for example loginForm.html sth like
<div>
<form>
....
</form>
</div>
and in pages where you want to put it use
<?php require('./include/loginForm.html') ?>; in place where you need it
Of course it need to be PHP page.
Good thing is to have also included header and footer in external html and include it on every php page ;D
if you want some js script in every page you need to add it manualy:
<script src="js/main.js"></script>
but it can be included in footer.
I am editing a WordPress PHP page and I want the page to block a particular external script from loading <div class="count_box">
Here is the script:
<script>
(function(document,script,id)
{
var js,
r=document.getElementsByTagName(script)[0],
protocol=/^http:/.test(document.location)?'http':'https';
if(!document.getElementById(id))
{
js=document.createElement(script);
js.id=id;js.src=protocol+'://widgets.changetip.com/public/js/widgets.js';r.parentNode.insertBefore(js,r)
}
}(document,'script','changetip_w_0'));
</script>
Is there a way I can affect this script to not load count_box? Or put in a script immediately after which blocks <div class="count_box">?
It's hard to know how it's being loaded without seeing any php. It looks like a widget called "changetip" from the code provided. Maybe temporarily deactivate it and see if that is causing it.
If that isn't it, check header.php and footer.php in your themes directory found in /wordpress/wp-content/themes/yourThemeName It will probably reveal itself somewhere in there.
I have used javascript to generate 2D bar-graphs in a HTML page.
When i am trying to load this HTML page containing bar-graph in to a div tag of some other HTML page using jQuery .load() function bar-graph (i.e, scripts) are not loading.
Please help on this issue.
For example i have bar-graph in xyz.html.
I am trying to load xyz.html in abc.html div tag using jquery .load() function.
Bar-graphs are missing.
Hoping for a reply, thanks for help in advance.
You should use iframe and load the html,I think,we can not directly load html in a div.
Are you generating the xyz.html output your self or is it created by some 3rd-party app?
If you're generating bar graphs your self, I recommend to generate just the content of body, not the whole site. Then the loading into abc.html should work correctly.
If they are not generated by you, use mhasan advice, but you shouldn't get the whole content oh html tag but only content of body tag.
BTW: have you an example of the script (js and html) somewhere to look at?
In jQuery you can use the
$(document).ready(function(){
});
to load the script when the page is ready. so you better put the chart generation script
inside this function in xyz.html (as said in your example).
You can also use this document.ready in your abc.html also to load the div.
Okey guys, so as the title says, i need some help about how i can create a Javascript and/or jQuery script which will 1st load all the html page elements (like divs etc.) and then display the page,once it is 100% loaded. I need this because right now, during the loading, one of my divs is moved up, and then when the page is loaded it goes into correct position. Cheers!
You could do this by initially setting body's css display to none and show it on document.ready().
E.g.
HTML:
<body style="display:none">
</body>
Script:
$(document).ready(function(){
$("body").show();
});
You could use clientside templates to build your page, for example the excelent jQuery.template plugin.
Simply don't build the page on the server, but do it on the client instead :)
I have a javascript for a specific page that I do not wish to be loaded in my header section. Is it possible to load it in the section of the HTML.
Currently I have all my js code inside the but I want to remove it to a seperate js file that I can load.
I tried using this but it did not work.
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-1.5.1.min.js"></script>
Thanks
Q1 : I have a javascript for a specific page that I do not wish to be loaded in my header section. Is it possible to load it in the section of the HTML.
-Yes you can load javascript any where you want, if writing inline code then make sure you add script tag around your code.
-also you can request files like in body
Q2: Currently I have all my js code inside the but I want to remove it to a seperate js file that I can load.
-- no problem in that, thats even better practice.
Q3 Requesting external file
to request external files you write below written fashion
<script src="http://file_name.js" type="text/javascript"></script>
It's not only possible (ref), it's frequently a good idea.
Putting your scripts as late in the page as possible, which frequently means just before the closing </body> tag, means the browser can parse and display your content before stopping to go download your JavaScript file(s) (if external) and fire up the JavaScript interpreter to run the script (inline or external).
Putting scripts "at the bottom" is a fairly standard recommendation for speeding up the apparent load time of your page.
Yes it is possible. Try and see.
For debugging, hardcode the jquery full path.
It is sometime recommended to load it at the end of the of the body, to make the main content of the page load faster.
Is it possible to load it in the section of the HTML.
Yes.
From the spec:
<!ELEMENT BODY O O (%block;|SCRIPT)+ +(INS|DEL) -- document body -->
SCRIPT is among the elements that may be a child of the BODY elements. Numerous other elements may also have SCRIPT children.
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-1.5.1.min.js"></script>
When I run echo base_url() I get my the hostname of my server. This would result in a URL such as example.comjs/query-1.5.1.min.js. You probably should drop that PHP snippet entirely and just use: src="/js/jquery-1.5.1.min.js" which would resolve to http://example.com/s/query-1.5.1.min.js.
Yahoo engineers recommendation for higher performance is to include your scripts at the end of your HTML, just before </body> tag. Therefore, it's even better.
To see where the problem is, you gotta first make sure that your js file is loading. User Firebug and go to scripts tab. Do you see your script? If not, then something is wrong with your path.
it should work...
Did you try to view the generated source and see if the PHP code indeed generated the right path?
beside that, it is recommended to load jQuery from a CDN such as google's :
https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js