I have one file named ad.php. In this file i load some ads from external pages.
(ad.php):
<script type='text/javascript' src='www.example.org'></script>...
And one file named: (index.php).
I want to load the contents of the file ad.php finished and then spend it in the index.php file.
I don't want, that the user loads the javascript files.
i tried some ways:
file_get_contents
curl
But the javascript files were loaded in the index.php by the user.
Is it possible to load the ad.php externally using php?
If you change your php.ini and set
allow_url_include = 1
allow_url_fopen = 1
you can use include("http://example.com/ad.php")
this would be the best way if you don't want to use JS.
If you want to use JS you could use XMLHttpRequests
Related
I have a file index.php and there is a main js script in its header.
I'm using Jquery load method to load other php file inside a div element:
$("#formHideinAjax").load('loginpass.php');
And as our friend explained here the main js file which had loaded in the header doesn't work in new imported file so I was forced to add the js file inside the loginpass.php too(Now I have two same js file, one in header and one in div that loads loginpass.php ! )
I know that this method of loading js file is not standard and sends more request to my server.
How can I fix this problem?
Well, it is explicitly said in $.load() documentation. I'm afraid you can't just paste <script></script> code into your DOM for browser to run it.
I'm afraid you have to send JavaScript code from your loginpass.php file (without <script></script> tags) and just eval it in your JavaScript
$("#formHideinAjax").load('loginpass.php', function () {
// eval JavaScript code from php file here
});
How can I load all html files in a folder into a content? I have about 125 html files in a folder src and need to load them in a content called .content.
$(".content").load("src/1.html");
is this doable on client side using JavaScript?
I belive you need to use PHP to get the numbers of files on a specific folder on your root directory.
http://php.net/manual/en/function.scandir.php
If you read this, you will be able to get the folder array by using PHP and they you can use JS or JQuery to do rest.
Sorry, I don't have a good understanding of the web, but:
When you load in an external script file into an html document, where does it hold or cache that file? It doesn't put it in the index.html file.
<html>
<head>
<script src="name_of_file"></script>
</head>
.....
I ask because I'm working with node.js, and I'm wondering if I list an external script file under my index.html page, I can send the javascript file to the client.
the browser will recognize the "src"="http://xxx/xx.js" of your script tag,and check if the resources(identified with URI:"http://xxx/xx.js") has cached in browser local cache dir(every browser has its own dir)
if the file exist and cache is not expired,the browser will directly load this file,otherwise browser will download the script file,and execute them when download finish.
This question has no good answer. A JavaScript program can be located anywhere on a server, It's just linked to with <script src=SCRIPT></script> Where SCRIPT is the relative or absolute path to the .js file. Check out This site for more info.
It's wherever the file is being served from. With what you've given and default setup, the file will be in the same directory as your index.html file
similiar How can I get the content of the file specified as the 'src' of a <script> tag? and Getting content of a script file using Javascript , I want to use script tag to load xml files for the use of a javascript code - only I need it to run locally.
so how can I access the content of the files loaded using script tag?
You can not achieve this one locally.
Loading the script will execute it and won't give you access to the src
so then the only option you would have is to load the file as an ajax call. But ajax calls don't work locally (due to security) .
I am trying to add an external javascript file to Codeigniter application.
I have placed my external js file in the "projectname/js/" folder.
Below is the script tag src in my view page.
src="http://localhost/needpcbcodeigniter/js/registration.js">
But I am getting a "Not found" error for the js file.
Most probably this is because the apache mod_rewrite is dealing with the js folder as a codeigniter controller name (as if you're calling http://localhost/projectname/index.php/js/registration.js)
Check your .htaccess to make sure it doesn't redirect when a valid filename is requested. Check it here
You should add an external javascript file to codeigniter in assets folder.
You should check some following steps :-
1) first fix your project base_url which is set in application/config/config.php like-
$config['base_url'] = 'http://localhost/yourprojectname/'
2) create a folder(e.g: js) in assets folder(at root of folder) for save all javascript files(e.g : registration.js).
3) on final step where you want to use javascript file use code like this-
<script src="<?php echo base_url();?>/assets/js/registration.js"></script>