Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 592405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:44:11+00:00 2026-05-13T15:44:11+00:00

Depending on which page I am, I would like the content of a javascript

  • 0

Depending on which page I am, I would like the content of a javascript function to change.

Example :

MasterPage

<script type="text/javascript">
    Cufon.now();
    Cufon.replace('p#characters', { fontFamily: 'Helvetica95-Black' });
</script>

Page A

<script type="text/javascript">
    Cufon.now();
    Cufon.replace('p#characters', { fontFamily: 'Helvetica95-Black' });
    Cufon.replace('p#others', { fontFamily: 'Helvetica95-Black' });
</script>

Because I do not want to do code repetition, I’m looking to a solution. I thought that maybe I could use something like a ContentPlaceHolder like this (but it doesn’t work) :

<script type="text/javascript">
    Cufon.now();
    Cufon.replace('p#characters', { fontFamily: 'Helvetica95-Black' });

    <asp:ContentPlaceHolder id="cphJS" runat="server" />
</script>

Any way to solve this kind of problem ?

UPDATE

What I will like to avoid is to have code like that :

// Add by MasterPage
<script type="text/javascript">
    Cufon.now();
    Cufon.replace('p#characters', { fontFamily: 'Helvetica95-Black' });
</script>

// Add by Page A
<script type="text/javascript">
    Cufon.now();
    Cufon.replace('p#others', { fontFamily: 'Helvetica95-Black' });
</script>

// Add by Page B
<script type="text/javascript">
    Cufon.now();
    Cufon.replace('p#main', { fontFamily: 'Helvetica95-Black' });
    Cufon.replace('p#menu', { fontFamily: 'Helvetica95-Black' });
</script>

Because that kind of code work but it’s not the cleaning way of doing it. I would prefer to have something like that :

<script type="text/javascript">
    Cufon.now();        
    Cufon.replace('p#characters', { fontFamily: 'Helvetica95-Black' });
    Cufon.replace('p#others', { fontFamily: 'Helvetica95-Black' });
    Cufon.replace('p#main', { fontFamily: 'Helvetica95-Black' });
    Cufon.replace('p#menu', { fontFamily: 'Helvetica95-Black' });
</script>

The result is the same. I only find that the second output is cleaner.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:44:11+00:00Added an answer on May 13, 2026 at 3:44 pm

    Why not simply add the additional code in a content place holder outside of the script tag?

    So, you would have something like:

    <head>
       <script type="text/javascript">
          // do some stuff
       </script>
       <asp:ContentPlaceHolder runat="server" id="someid" />
    </head>
    ...
    

    Or, you might collect functions in an array early in the page and then execute them later on like so:

    In the <head>:

    var callbacks = [];
    function addCallback(arg) {
       callbacks.push(arg);
    }
    

    At some other location:

    addCallback(function() {
       ...
    });
    

    And then at the bottom of the page, just before the </body>:

    for (var i = 0; i < callbacks.length; i++) {
       var c = callbacks[i];
       if (c && c instanceof Function)
          c();
    }
    

    Could you provide more details about the requirements? Ex: What the above code is supposed to do, does it have to be executed all at once, does it depend on local variables that are created, does it have to run at a certain time, etc.

    Edit:
    Using a content placeholder in a new MVC project seemed to work fine for me. Intellisense didn’t pick it up but it rendered correctly. Here’s what the code looks like for me.

    In the master page:

    ...
    <script type="text/javascript">
        var inTheMasterPage;
        <asp:ContentPlaceHolder runat="server" id="js1">
        </asp:ContentPlaceHolder>
    </script>
    

    …

    In the page:

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
    
    <asp:Content runat="server" ContentPlaceHolderID="js1">
        var inThePage;
    </asp:Content>
    ...
    

    And the rendered HTML:

        <script type="text/javascript"> 
            var inTheMasterPage;
    
        var inThePage;
    
        </script> 
    </head> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple function in which an array is declared with size depending
Since I need to do some checks depending on which control is on focus
I have an SSIS package, which depending on a boolean variable, should either go
I want to override OnMouseClick and OnMouseDoubleClick and perform different actions depending on which
I have an application which had optional extras depending on if the user has
Depending on my mood I seem to waffle back and forth between wanting a
I need my application to behave differently depending on whether Vista UAC is enabled
I have an executable that depending on the command line switch supplied looks something
I came across the case where depending on the execution path I may need
I want to render a partial depending on a selection in selection box. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.