Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过编程在窗口中打开外部URL,链接会附加到站点_Javascript - Fatal编程技术网

Javascript 通过编程在窗口中打开外部URL,链接会附加到站点

Javascript 通过编程在窗口中打开外部URL,链接会附加到站点,javascript,Javascript,我允许用户通过jquery插件添加标签。在给定标记的tag click事件发生后,我解析出tagLabel并提取URL(如果存在)。一旦我有了URL,我就会打开外部链接。它实际上是将链接附加到我现有的应用程序中,例如: localhost/App1/www.cnn.com $('#myTags').tagit({ select: true, sortable: true, editable: true, allowSpaces: true, trigger

我允许用户通过jquery插件添加标签。在给定标记的tag click事件发生后,我解析出tagLabel并提取URL(如果存在)。一旦我有了URL,我就会打开外部链接。它实际上是将链接附加到我现有的应用程序中,例如:

localhost/App1/www.cnn.com

$('#myTags').tagit({
    select: true,
    sortable: true,
    editable: true,
    allowSpaces: true,
    triggerKeys: ['enter', 'comma', 'tab'],
    onTagClicked: function (evt, ui) {
        var tagy = ui.tagLabel;
        var result = URI.withinString(ui.tagLabel, function (url) {
            var URL = url;
            window.open(url, '_new');
        });
    }
});
应该是

www.cnn.com

$('#myTags').tagit({
    select: true,
    sortable: true,
    editable: true,
    allowSpaces: true,
    triggerKeys: ['enter', 'comma', 'tab'],
    onTagClicked: function (evt, ui) {
        var tagy = ui.tagLabel;
        var result = URI.withinString(ui.tagLabel, function (url) {
            var URL = url;
            window.open(url, '_new');
        });
    }
});

您需要确保url以
http
https

开头。您需要确保url以
http
https
开头