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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.