30Mar/111

Need to fire onload event on script element?

I've recently had a client request to have a "desktop quote" page that used a third party API to get stock quote information in a popup. The interesting thing about the API is to access the data you modified the src of a script tag so it would return javascript that created an object that you could use to access the stock quote data.

I have a dropdown list of possible comparison quotes to be loaded dynamically. I attach an onchange event handler to it so I can refresh the page with the appropriate query string (need to refresh page every 15 minutes to get latest data). Here is where I add the event handler.

dojo.query("#bench").connect("onchange", this, function(e) {
    var url = getUrl();
    if(url != null)
        window.location = url + "?ticker=" + e.target.value;
});

On page load using dojo.addOnLoad(), I call the below code if there is a query string parameter named ticker and the value is valid. This snippet adds a script tag to the DOM under the body tag. Then attaches an onload event to the script element.

var n = dojo.create("script", {
    type: "text/javascript",
    src: "http://apps.shareholder.com/irxml/irxml.aspx?COMPANYID=abc&PIN=abc123&FUNCTION=StockQuote&OUTPUT=js2&TICKER=" + ticker
}, dojo.body(), "first")
if (dojo.isIE)
    dojo.query(n).connect("onreadystatechange", this, function() {
        populateData("Comp");
    });
else
    dojo.query(n).connect("onload", this, function() {
        populateData("Comp");
    });

Notice the if(dojo.isIE)? The onload event is not fired in IE for the script element (works fine in firefox and chrome). However, the onreadystatechange event is. This ensures that the objects/code in the the dynamically injected javascript gets executed before the populateData function is called.


Filed under: Technology 1 Comment
20Sep/100

Visual Studio Unable to add to the Web site Unable to add file Access is denied

I am trying to publish my project from my development machine to the staging environment. I would right click the project in visual studio and click publish. Most of the files would publish just fine, but a few were giving me problems. In the output log, there were multiple error messages, all stating:

Unable to add ‘XXX.ext’ to the Web site. Unable to add file ‘XXX.ext’. Access is denied.


2Sep/100

Sitecore – Encoding Special Characters In Fields

If web standards compliance is one of your top priorities and you have a site core implementation, then you may want to continue reading. Are you tired of seeing & instead of & on your site? Not sure of the best way to encode them? I have created a processor that snaps into the renderField pipeline. The only caveat is that in order for this code to run you need to use the FieldRenderer.Render(Item, FieldName) method. Which, in my opinion, you should always be using anyway.


25Aug/100

Sitecore – FieldRenderer.Render(item, fieldname) returning “” empty string

Today I spent 2 hours trying to debug why FieldRenderer.Render() was returning an empty string.

It was working yesterday and the code didn't change, so what was it?


11Aug/100

WARN Could not create an instance of the counter …

Sitecore log files bigger than they should be? Are you finding "Could not create an instance of the counter" ... numerous times? Well this seems to be a common problem especially if you have manually installed Sitecore. The problem is that the counters are not installed. Sitecore has realized this and created a script to install the necessary performance counters.


Close
E-mail It