How to call a javascript method from XAML

T

tarinip

Hi,

How to call a javascript method from XAML. I am using C# .

In the following example, When I click button1, I wish to call a
method by name "SetValue(somevalue)"
of TestIndex.html file. Here SetValue is a javascript method present
in TestIndex.htm file.

Let me know if you need any further information.

Thanks in Advance.

Thanks
Tarini


----------------------------

<Window x:Class="wpfsample1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="wpfsample1" Height="755" Width="1032"<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.121785006260434*" />
<ColumnDefinition Width="0.0273246391943384*" />
<ColumnDefinition Width="0.36610333628965*" />
<ColumnDefinition Width="0.484787018255578*" />
</Grid.ColumnDefinitions>
<Button Height="23" Margin="63,83,18.3874239350913,0"
Name="button1" VerticalAlignment="Top" Click="OnBtnClick">Button</
Button>
<Frame Content="Frame" Margin="13.3874239350913,3,69,1"
Name="frame1" Source="http://localhost/TestIndex.html" Grid.Column="2"
Grid.ColumnSpan="2" />

</Grid>
</Window>
 
G

Guest

AFAIK, the Frame content is isolated from the outer content and cannot call
the JS script.
 
D

Diego Jancic

You can only do it id both pages are on the same domain.
To call a function inside a frame:
document.getElementById("frame_id").contentWindow.myFunction();

.... and to call a function in the parent window:
window.parent.myFunction();

Diego
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top