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

  • Home
  • SEARCH
  • 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 6983411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:24:56+00:00 2026-05-27T18:24:56+00:00

I am creating dynamic sites with the same code base, where I will need

  • 0

I am creating dynamic sites with the same code base, where I will need to display the appropriate Google ads Javascript code, based on some logic.

In my .Net 4, MVC3 environment, I have setup the following scenario:

Navigating to http://www.mysite.com/script_processor/ returns the following text:

function doAlert(v1, v2){alert('Called alert()' + v1 + ' : ' + v2);}

This text come out of my model as such:

page.stringResponse = "function doAlert(v1, v2){alert('Called alert()' + v1+ ' : ' + v2);}";   

I can then do something like this from a separate site/page:

<script type="text/javascript" src="http://mysite.com/script_processor/">
</script>
<script type="text/javascript">
    doAlert('string 1', 'string 2');
</script>

As you would expect, I get an alert box with “Called alert() string 1 : string 2”, so the function on mysite.com is accessible from site 2.

Obviously when I do a view source form the page, I only see the doAlert() call, and not the content of the function that sits on mysite.com.

Now, instead of doAlert() on mysite.com, I want to have a function that dynamically writes out javascript that can will be seen on site 2 when it’s called.

I created a model method:

public GetResponsePage GetPageResponse(string V1, string V2)
{
    var page = new GetResponsePage();
    page.stringResponse = "<script type=\"text/javascript\">document.write('testing injected Javascript.');alert('value of v1: " + V1 + "value of v2: " + V2 + "');</script>";
    return page;
}

When navigating to the route, I see the popup, and the “testing injected Javascript.” on the page.

When I reference this from site 2, I don’t see the popup, nor do I see “testing injected Javascript” in the page source.

As I mentioned I will later replace this with the JS code for the appropriate Google Ads js code.

I don’t think this is working quite right… what am I missing?

Thanks.

  • 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-27T18:24:56+00:00Added an answer on May 27, 2026 at 6:24 pm

    You can use the ever evil eval to dynamically execute JavaScript. The JavaScript you pass in can also declare functions.

    eval("function doAlert(v1, v2){alert('Called alert()' + v1 + ' : ' + v2);}");
    

    I’m not sure exactly what you’re trying to accomplish, but you could put an eval call like this wherever you want:

    function createDoAlertFunction(){
        eval("function doAlert(v1, v2){alert('Called alert()' + v1 + ' : ' + v2);}");
    }
    

    Just note though, that this should be avoided. Stick to declaring your functions the old fashioned way, like you already are.

    EDIT

    Oh, you want MVC to to inject JavaScript dynamically. MVC has a JavaScriptResult, but it looks like its use is strongly, strongly discouraged.

    Nonetheless, here’s a link that shows its use

    public ActionResult DoSomething() {  
       string s = "$('#some-div').html('Updated!');";  
       return JavaScript(s);  
    }  
    

    and why it’s not a good idea

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to integrate the functionality of creating dynamic pages (like google sites) to
I am having some trouble creating a experimental 'dynamic' style website. The site is
I am creating dynamic menus and submenus in php.... Can't know where to start....
I'm creating dynamic templated XAML designs that I would like to convert to PNG
which method do you prefer for creating dynamic sql queries? formating or streaming? Is
Was wondering if anyone had any smart approaches to creating dynamic vanity user urls
Im creating a dynamic MenuBar from xml file, and binding events to menu items
I'm creating an dynamic image, which creates headers on my page using PHPs GD-library.
I am creating a dynamic cursor and I would like to loop over the
What choices do I have for creating stateful dynamic content in an ASP.Net web

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.