browse by category or date

Website Description

Originally was hosted within Share Investor/Listed Company hosting service, but it is now self hosted. The website displays a stock ticker using an iframe in which the source is located at Listed Company’s server.

<iframe width="600" scrolling="no" height="28"
        frameborder="0" id="home_ticker" 
	style="background-color: transparent;" 
	src="http://xxx_company_name_xxx.listedcompany.com/includes/stock_ticker.html">
 </iframe>

 

Symptom

In Internet Explorer, the ticker is not running.
stock_ticker_err

But it runs properly on Chrome, Firefox (yet to test it in Opera and Safari).
stock_ticker

 

Cause

Upon debugging in IE’s Developer Tools, we found out that jQuery was throwing SCRIPT5: Access is denied.
ie_devtool

Further investigation shown that this is caused by cross-domain restriction in IE, as discussed in here and here.

 

Solution

Since this is a cross-domain problem, we need to create a simple proxy that will fetch the content from Listed Company’s server.

  1. Create a proxy folder in the website’s root folder.
  2. Download http://xxx_company_name_xxx.listedcompany.com/includes/stock_ticker_script.js and save it as stock_ticker.js in folder created in the first step. (Don’t worry, the script file is under dual licensed under the MIT and GPL).
  3. Create proxy.aspx inside the folder above.
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Net" %>
    <%@ Import Namespace="System.Net.Cache" %>
    
    <script runat="server">
        public void Page_Load(object sender, System.EventArgs e)
        {
            Response.Clear();
    		DirectoryInfo dir = new DirectoryInfo(Server.MapPath("/proxy"));
            FileInfo cache = new FileInfo(dir.FullName + "\\_stock_ticker.html");
            if (cache.Exists && cache.LastAccessTime >= DateTime.Now.AddMinutes(-10))
            { 
                //if the cache file is updated in the last 10 minutes, return the cache file instead
                Response.WriteFile(cache.FullName);
            }
            else
            {            
                try
                {
                    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(
                                         "http://xxx_company_name_xxx.listedcompany.com/includes/stock_ticker.html");
                    //don't cache
    	        req.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                    StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream());
                    String content = reader.ReadToEnd();
                    reader.Close();
                    //replace the js file the our local copy
                    content = content.Replace("/includes/stock_ticker_script.js", "stock_ticker.js");
                    StreamWriter writer = new StreamWriter(cache.OpenWrite());
                    writer.Write(content);
                    writer.Close();
                    Response.WriteFile(cache.FullName);
                }
                catch (Exception ex)
                {
                    if (cache.Exists)
                        Response.WriteFile(cache.FullName);
                    else
                        Response.Write(ex.ToString());
                }
            }      
        }
    </script>
    
  4. Replace the iframe’s src
    <iframe width="600" scrolling="no" height="28"
            frameborder="0" id="home_ticker" 
    	style="background-color: transparent;" 
    	src="/proxy/proxy.aspx">
     </iframe>
    
  5. That’s all folks! I hope it helps. Cheers!

    GD Star Rating
    loading...
    [Solved] Stock Ticker Widget From Listed Company / Share Investor Error in Internet Explorer, 4.0 out of 5 based on 1 rating

    Possibly relevant:

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Incoming Search

asp.net, browser, c#, internet explorer, jquery

No Comment

Add Your Comment