durandaldurandal-2.0

How to run scripts in Durandal View


I have a Durandal App.

On one of the pages, I need to using some existing javascript which I do not want to modify.

However, if I use something like this in the view.html:

<script>alert("test");</script>

the alert is not triggered.

Normally such code would go into the ViewModel. However, in this case, I want to use a Sound Recorder and there is a number of scripts that make this up and I would like to use them as is.

In other words, I would like view.html to act like a regular html page.

When I modify the router to use *.html, it throws an error.

{ route: 'recorder', moduleId: 'views/recorder.html', nav: true }

Is there a way to resolve this?


Solution

  • Taking the recommendation from the OP and posting my comment as an answer:

    According to Rob Eiserberg (the author of Durandal), don't do this. The reason being is that all script tags within the view are stripped. I'm sure this is done as a security precaution. Additionally, you could implement the solution recommended here.