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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:35:10+00:00 2026-05-27T08:35:10+00:00

I am building a web widget which will be very easy to integrate. Say

  • 0

I am building a web widget which will be very easy to integrate. Say http://www.bicycleseller.com/ wants to integrate my widget on his web page. All he has to do is copy and paste the following to the head section of his page:

<script src="http://www.widgetprovider.com/widget.js" type="text/javascript"></script>
<script>
Widget.create("123456accessKeyOfBicycleSeller").render("myWidget");
</script>

and <div id="myWidget"></div> to anywhere in the body section. The widget will be displayed in that div.

I, as the widget provider, host the widget.js:

var Widget = new function () {

    this.url = "www.widgetprovider.com/widget.jsp";
    this.name = "";
    this.parameters = "width=400,height=200,screenX=750,screenY=300,resizable=0";


    this.create = function (accessKey) {
        this.accessKey = accessKey;
        return this;
    };


    this.render = function (divId) {
        // make sure the document is fully loaded and place the widget on BicycleSellers page.
        // when the widget (a jpeg) is clicked, a jsp page I host will popup.
        window.onload = function () {
            document.getElementById(divId).innerHTML = '<img src="images/widget-image.jpg" onclick="Widget.display()"/>';
        };
        return this;
    };

    this.display = function () {
        // open a popup window that displays a page I host.
        var popup = window.open(this.url + "?accessKey=" + this.accessKey, this.name, this.parameters);
        popup.focus();
        return this;
    };
};

So, the BicycleSeller places the widget on his page and when his users click on it, a popup appears that show them content from a page I host.
However, each webmaster that wants to embed my widget, has to provide an accessKey, unique to them, because the popup’s content will be dependent on that.

My questions are:

1) In this scenario, anyone who goes to bicycleseller.com and views the HTML source can see his accessKey which is hard-coded in the head section. Then they can just navigate to www.widgetprovider.com/widget.jsp?accessKey=123456. I don’t want that to happen. What can be done about this? For instance; I was looking at the source of Facebook and they seem to hide everything very well.

2) Is this a good way to go on building a widget? I was thinking of a lightbox rather than a popup window (which might be blocked by a popup blocker – although in this example it does not). Any comments/suggestions welcome.

3) If I try to place to widgets and write Widget.create("key1").render("div1"); Widget.create("key2").render("div2"); two images are generated. But when clicked, both popups display key1 s information. This is because the Widget class in widget.js is singleton. If I don’t make it singleton, then I can’t place the image’s onclick attribute (Widget.display()). What do I do for that?

Looking for help on the three questions. Any help will be greatly appreciated. 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-27T08:35:10+00:00Added an answer on May 27, 2026 at 8:35 am

    Your server can validate the “Referer” header of the request. This would stop casual users from viewing the popup content out of context by entering the URL in the address bar, or by following a third party link. Headers can be spoofed, but this takes some effort and is not a standard browser feature.

    You will not be able to stop a hacker from loading the popup out of context on their own computer.

    On the issue of popups being a good idea, I think something inline would be better, but also more work and less portable, so you have to decide if popups are good enough.

    To make Widget not be a singleton, instead of:

    $(window).load(function () {
        document.getElementById(divId).innerHTML = '<img src="images/widget-image.jpg" onclick="Widget.display()"/>';
    });
    

    use:

    var widget = this;
    $(window).load(function () {
        var image = document.createElement("img");
        image.src="images/widget-image.jpg";
        image.onclick = function() { widget.display() };
        document.getElementById(divId).appendChild(image);
    });
    

    By setting onclick to an actual function instead of the code for a function, you can refer back to the instance of Widget through the closure.

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

Sidebar

Related Questions

I'm a lead developer on a project which is building web applications for my
I`m looking for opinion which one is better for building web applications(web sites). I
I'm building a web app that many people will be using at the same
Good Evening, I'm building a website which will will look something like this: So
When building a multi-lingual website (with ASP.NET web forms), I'll use an HTTP module
I am building a web application in which I would like to include the
I'm building web application (in this context the client) which talk with a different
I am just going to be honest and say that I hate building web
I have been investigating building web parts for sharepoint 2010 and currently have a
Is there a programming language suitable for building web applications, that is compiled, strongly-typed,

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.