Oct 24
When talking about Silverlight and Flash, one should not miss out the browser integration part.
The sample below demonstrate three basic browser integration techniques: open popup, modify CSS and amend HTML content.
This is the first sample only. I will try to come up the 2th, 3th, 4th.. 10th samples later on.
Comparison
Flash implementation: 30 minutes (Implemented First)
Silverlight implementation: 40 minutes
What’s the difference?
- Browser Integration: navigateToURL [AS3] vs HtmlPage [C#]
Source codes
JavaScript Sample 1 [Flash 9, AS3] (15 KiB, 1,298 hits)
JavaScript Sample 1 [Silverlight 2, C#] (10.5 KiB, 1,402 hits)
Flash
Silverlight
Browser Integration: navigateToURL [AS3] vs HtmlPage [C#]
I think you can do whatever you want in Flash. It’s because you can write JavasScript directly in AS3.
// AS3
// open popup
var js:String = "window.open('URL','_blank','height=300,width=300');";
var url : URLRequest = new URLRequest("javascript:" + js+ " void(0);");
navigateToURL(url, "_self");
// modify CSS
var js:String = "document.body.style.backgroundColor='#FF0000';";
// amend HTML content
var js:String = "document.getElementsByTagName('h1')[0].innerText = ‘Value’;”;
Silverlight provided a set of API to manage the HTML DOM. However, I am not sure if you can call your own JavaScript directly as in Flash.
// C#
// open Popup
HtmlPage.PopupWindow(new Uri("URL", UriKind.Absolute)
, "_blank",
new HtmlPopupWindowOptions() { Width = 300, Height = 300});
// modify CSS
HtmlDocument document = HtmlPage.Document;
document.Body.SetStyleAttribute("background", "#0080FF");
// amend HTML content
HtmlDocument document = HtmlPage.Document;
ScriptObjectCollection collections = document.GetElementsByTagName("h1");
HtmlElement htmlElement = (HtmlElement) collections[0];
htmlElement.SetProperty(”innerHtml”, “This is Silverlight Title”);

October 24th, 2008 at 3:05 pm
The popup window doesn’t appear in both cases in FireFox but opens a new tab , is a way around this ? , off coarse I can change from FireFox options but I ask if I can force it !!!!!
Thanks
October 24th, 2008 at 5:30 pm
I think you can call your own JavaScript in Silverlight using the following method:
HtmlPage.Window.Eval()
October 25th, 2008 at 7:50 am
Yes, you can call javascript directly from Silverlight.
Silverlight is clientside like javascript, so just think of all that silverlight code hiding in a silverlight box on the page, it’s right next door to any javascript on the same page.
October 27th, 2008 at 1:16 am
Mina Saad, I think most of the browsers will either block the pop up or open in a new tab.
There should be no way to force Firefox to do it, but I think you may change the Firefox settings and make it works only.
TomC, thanks for the suggestion, I will try to use it next time~
October 29th, 2008 at 11:25 pm
ı dont believe you .
why do you make silverlight first?
ı think you take money from microsoft.
silverlight is new is cheep.ı dont believe it’s advanced about in scripts and programming
November 5th, 2008 at 4:16 am
Looks like the Flash/Flex version has a bug in it. If you click one of the buttons and release the buttons fly around and go crazy. In the Silverlight version it looks to work fine.
November 6th, 2008 at 4:52 pm
In Mac osx, with safari Open Popup and Change Title do not work.
December 16th, 2008 at 7:50 pm
its up to you.if your programming capacitie good you can fine button and more whats.
April 27th, 2010 at 7:12 pm
Hi,
It is working fine at site here but I’ve downloded sample code, migrate to SL 3 and runed.
I’ve got error on JS - >Error: Permission denied
var H=((”https:”==document.location.protocol)?document.location.toString():”");
Have you any idea about the reason for this?
I’ve got the same problem with HyperlinkButton.
July 14th, 2010 at 2:40 am
[...] Flash Silverlight Download [...]