简体   繁体   English

TinyMCE 4自定义浏览器弹出窗口MVC

[英]TinyMCE 4 Custom Browser Popup Window MVC

Is it possible to add a custom button which will open a new browser window to a specific URL? 是否可以添加自定义按钮,以将新的浏览器窗口打开到特定的URL?

There is currently a Preview button, which opens a window but shows the content used with in the WYSIWYG Editor, however I need the user to see the WYSIWYG content as it is actually rendered with the respective View. 当前有一个“预览”按钮,它会打开一个窗口,但显示所见即所得编辑器中使用的内容,但是我需要用户查看所见即所得的内容,因为该内容实际上是使用相应的View渲染的。

Edit.cshtml Edit.cshtml

<script type="text/javascript" src="/Scripts/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
    selector: "textarea",
    theme: "modern",
    height: 300,
    language: 'en_GB',
    browser_spellcheck: true,
    verify_html: false,
    plugins: [
    "advlist autolink lists link image charmap print preview hr anchor pagebreak",
    "searchreplace wordcount visualblocks visualchars code fullscreen",
    "insertdatetime media nonbreaking save table contextmenu directionality",
    "emoticons template paste textcolor colorpicker textpattern moxiemanager imagetools"],
    toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media | forecolor backcolor emoticons | preview2",
    image_advtab: true,
    file_browser_callback: function (fieldName, url, type)
    {
        var w = window,
            d = document,
            e = d.documentElement,
            g = d.getElementsByTagName('body')[0],
            x = w.innerWidth || e.clientWidth || g.clientWidth,
            y = w.innerHeight || e.clientHeight || g.clientHeight;

        var cmsUrl = '/Scripts/FileManager/Index.html?&field_name=' + fieldName + '&langCode=' + tinymce.settings.language;

        if (type == 'image')
        {
            cmsUrl = cmsUrl + "&type=images";
        }

        tinyMCE.activeEditor.windowManager.open({
            file: cmsUrl,
            title: 'FileManager',
            width: x * 0.8,
            height: y * 0.8,
            resizable: "yes",
            close_previous: "no"
        });
    },
    setup: function (ed) {
        ed.addButton('preview2', {
            title: 'Preview',
            image: './/',
            onclick: function () {
                tinyMCE.execCommand('mceInsertContent', false, 'Hello!!');
            }
        });
    }
});

I have added a custom button, but I need the current 'tinyMCE.execCommand' to initiate a new browser window with specific URL, currently it does nothing more than insert content. 我添加了一个自定义按钮,但是我需要当前的“ tinyMCE.execCommand”来启动具有特定URL的新浏览器窗口,当前它仅能插入内容。

Any help would be much appreciated :-) 任何帮助将非常感激 :-)

By using window.open(url,'_blank'); 通过使用window.open(url,'_blank'); in javascript you can do this, see this simple example: 在javascript中,您可以执行此操作,请参见以下简单示例:

$("#mybutton").on("click", function(){
    window.open("http://stackoverflow.com",'_blank');
});

Here's the working example on jsfiddle 这是jsfiddle上的工作示例

You just have to replace the current code inside onclick by 您只需要替换onclick中的当前代码为

window.open(" http://stackoverflow.com ",'_blank'); window.open(“ http://stackoverflow.com ”,'_ blank');

您需要使用

window.open(url,'_blank');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM