开发者

Asp.net an TinyMce integration logic for JavaScript

I have a ASP.NET 4 page an开发者_Go百科d I am using tinyMce.

My aim is to change toolbar setting for tinyMce depending on "Role" associated to logged User.

To solve it my idea is to include different version of tinyMce JavaScript code using some logic.

My questions are: - do you know a better solution? - how to include JavaScript inside the Head of the page pro grammatically?

Thanks


It sounds as if you're not using MVC with MasterPages (which has a built in method for including such a JavaScript). If you're using web forms, you can put a Literal in the head of your document and assign its text value from the code behind:

<asp:Literal ID="myTinyMCEScript" runat="server" />

...

string adminScriptText = "some javascript to format for admins";
string userScriptText = "some javascript to format for knuckledraggers";
this.myTinyMCEScript.Text = (myUserRole == "admin") ? adminScriptText : userScriptText

Not terribly elegant, but effective.

Edit:

To use a file:

string adminScript = "<script language=\"javascript\" type=\"text\\javascript\" src=\"link/to/adminscript.js\"></script>";
string userScript = "<script language=\"javascript\" type=\"text\\javascript\" src=\"link/to/userscript.js\"></script>";

Since you want to store it in a file, and javascript is run in plain text at the browser, you might as well just stick it in a js file and include that js file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜