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.
But it runs properly on Chrome, Firefox (yet to test it in Opera and Safari).
Cause
Upon debugging in IE’s Developer Tools, we found out that jQuery was throwing SCRIPT5: Access is denied.
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.
- Create a proxy folder in the website’s root folder.
- 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).
- 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>
- 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>
That’s all folks! I hope it helps. Cheers!
loading...
About Hardono
Incoming Search
asp.net, browser, c#, internet explorer, jquery