Greg Gum
Greg Gum

Reputation: 37909

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?

Upvotes: 0

Views: 107

Answers (1)

Brett
Brett

Reputation: 4269

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.

Upvotes: 1

Related Questions