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 637481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:37:42+00:00 2026-05-13T20:37:42+00:00

I need some advice for the best approach to use in developing embeddable widgets

  • 0

I need some advice for the best approach to use in developing embeddable widgets that my site users could use to show our content on their site.

Let’s say we have some content which uses a jQuery plugin to be rendered, and we want to give our customers an easy way to embed it in their websites.

One option could be of using an IFrame, but as we know this is quite invasive and has some problems. I’d like to know your opinion on that, too.

Another approach could be giving a code like this, to show item #23:

<DIV id="mysitewidget23"><script src="http://example.com/scripts/wdg.js?id=23" /></DIV>

And somehow (help needed here…) creating the wdg.js server-side script to inject content, jQuery, needed plugins, inside the DIV.

This looks more promising, since the user can customize to a certain extent the style of the DIV, and no IFRAME is needed. But which is the best and more efficient way to do this in ASP.NET MVC?

There are of course many other approaches to achieve what we need.

  • 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-13T20:37:42+00:00Added an answer on May 13, 2026 at 8:37 pm

    JSONP is one way to do this. You start by writing a custom ActionResult that will return JSONP instead of JSON which will allow you to work around the cross-domain Ajax limitation:

    public class JsonpResult : JsonResult
    {
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
    
            if (!string.IsNullOrEmpty(ContentType))
            {
                response.ContentType = ContentType;
            }
            else
            {
                response.ContentType = "application/json";
            }
    
            if (ContentEncoding != null)
            {
                response.ContentEncoding = ContentEncoding;
            }
    
            if (Data != null)
            {
                var request = context.HttpContext.Request;
                var serializer = new JavaScriptSerializer();
                if (null != request.Params["jsoncallback"])
                {
                    response.Write(string.Format("{0}({1})",
                        request.Params["jsoncallback"],
                        serializer.Serialize(Data)));
                }
                else
                {
                    response.Write(serializer.Serialize(Data));
                }
            }
        }
    }
    

    Then you could write a controller action that returns JSONP:

    public ActionResult SomeAction()
    {
        return new JsonpResult
        {
            Data = new { Widget = "some partial html for the widget" }
        };
    }
    

    And finally people can call this action on their sites using jQuery:

    $.getJSON('http://www.yoursite.com/controller/someaction?jsoncallback=?',
        function(json)
        {
            $('#someContainer').html(json.Widget);
        }
    );
    

    If users don’t want to include jQuery on their site you might write JavaScript code on your site that will include jQuery and perform the previous getJSON call, so that people will only need to include a single JavaScript file from the site as in your example.


    UPDATE:

    As asked in the comments section here’s an example illustrating how to load jQuery dynamically from your script. Just put the following into your JavaScript file:

    var jQueryScriptOutputted = false;
    function initJQuery() {
        if (typeof(jQuery) == 'undefined') {
            if (!jQueryScriptOutputted) {
                jQueryScriptOutputted = true;
                document.write("<scr" + "ipt type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"></scr" + "ipt>");
            }
            setTimeout("initJQuery()", 50);
        } else {
            $(function() {
                $.getJSON('http://www.yoursite.com/controller/someaction?jsoncallback=?',
                    function(json) {
                        // Of course someContainer might not exist
                        // so you should create it before trying to set
                        // its content
                        $('#someContainer').html(json.Widget);
                    }
                );
            });
        }
    }
    initJQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some advice about a best-approach for this problem: I've fallen madly in love
I need some advice on the best approach to take for the following. I
Need some best practice advice here... Navigation based application. Root view is a UITableView
I need some advice. I’m building an app that has a sequence of 4
I need some advice regarding which database I should use. I want to create
I need some advice on what kind of pattern(s) I should use for pushing/pulling
I'm writing a GP that I need some advice on for crossover and mutation
I'm looking for some advice/opinions on the best way to approach creating a sort-of-dynamic
I need some advice on how to successfully update mutiple rows in my database
I need some advice of how to setup my tables I currently have a

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.