SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Placing HTML Code On Other Sites Using Javascript

    I've partnered with a couple of websites and we need an easy way to play a consistent set of HTML links between our sites at the top of our pages. I'd like to do this using a single javascript file placed in a central location and then call this javascript from each site.

    But I'm not a javascripty programmer. I've looked at other files and tried to construct something to do it, but it's not working. Maybe you can tell me where I'm going wrong.

    THE MENU.JS FILE
    On one site, say domain1.com, I want to create a javascript file called menu.js.

    Here is an example of the code for menu.js:

    Code:
    function Go(){
    document.write("<a href="http://www.link1.com">Link1 Name</a></BR>");
    document.write("<a href="http://www.link2.com">Link2 Name</a>")
       }
    That's it for menu.js. If the syntax is wrong, please tell me, because my whole project is not working out. The HTML in there would be more complicated, using tables and such, but the concept is there for this discussion.

    CALLING MENU.JS FROM ANOTHER WEBSITE
    On each of the websites, in the HTML of each page, right below the BODY tag, I'd include the following:

    Code:
       <script type='text/javascript'>
    function Go(){return}
    </script>
    	  <script type='text/javascript' src="http://domain1.com/menu.js">
       </script>
    Well, it's not working. Any ideas where I'm going wrong?

    Any advice would be greatly appreciated.

    Thanks.

    Sean
    Scarsdale Technologies, Inc.
    http://www.scarsdaletech.com

  2. #2
    SitePoint Addict BenANFA's Avatar
    Join Date
    Apr 2003
    Location
    Bath, UK
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have the that is trying to call MENU.JS wrong you are defining a function Go youself instead of calling the one provided, try

    PHP Code:
    <script type='text/javascript' src="http://domain1.com/menu.js"></script>
    <script type='text/javascript'> 
      Go(); 
    </script> 
    Alternitively in the file MENU.JS do not have a function use the following code

    PHP Code:
    document.write("<a href='http://www.link1.com'>Link1 Name</a></BR>" ); 
    document.write("<a href='http://www.link2.com'>Link2 Name</a>" ); 
    Then in the calling page just put

    PHP Code:
    <script type='text/javascript' src="http://domain1.com/menu.js"></script> 
    where you want the menu.

    Also note the the code that you have for MENU.JS you have used multiple " in the string without escaping them, I have provided an edited solution.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See if this is of any use.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •