Jump to content

How to make function that we can call from another web page?


joseph

Recommended Posts

How do we call a certain function from another webpage (function.html) to show in this particular page (index.html)?

 

For example if I have this in my function.html

 

<a href="http://sitename.com">sitename</a>

 

and I would like to call that function to show in the index.html without using iframes.

 

Thanks.

I'm testing my site locally on a wamp server.

 

I have a links.php having:

<?php
function topnav() {
echo'
<a href="...."></a>
}
';
?>

 

It does not seem to work if I call it in index.php:

<?php topnav(); ?>

 

I want to call the topnav() in index.php so that I don't to edit the links everytime I add a new webpage.

 

@jason_kraft: I also tried <?php include("filename.php"); ?> however it gives me an error

Warning: include() [function.include]: URL file-access is disabled in the server configuration...

 

Does javascript has something like this? I might need it in javascript codes because my website is currently in .html extensions.

i'm assuming you are a new programmer?

but yeah hey try including a .js file with all your functions and linking it in your .html file

 

so you will have a "functions.js" file with contents

function functionname() {
...
}

 

and your "index.html" file just link the .js file in the head section

 

<head>
<title>Page Title</title>
...
        <script type="text/javascript" src="functions.js"></script>
</head>

 

but i recognize that this is not a php issue.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.