automatically launching an external website in a new window with the link added to the current site

With the help of a jQuery plugin, users can add tags. When a tag is clicked, I extract the tagLabel and search for a URL. If a URL is found, I open the link externally. The link is appended to my existing application like this:

localhost/App1/www.cnn.com

It should actually be

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');
        });
    }
});

Answer №1

Always ensure that the URL commences with either http or https

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm unsure of which tools and languages to use for web development. Can you provide

My journey into programming began in January of this year, and I have made significant progress since then. I have gained knowledge in JavaScript, Ruby on Rails, HTML, CSS, jQuery, and occasionally dabble in Clojure. However, my true passion lies in JavaSc ...

Can you explain the functionality of this require() statement?

Currently, I'm reviewing the code example found at https://github.com/mjhea0/passport-local-express4 During my examination, I came across this require() statement. app.use(require('morgan')('combined')); In all of my previous ex ...

Issue with Firefox pageMod addon: window.location not functioning properly

I'm developing a unique Firefox Add-on that implements page redirects based on keyboard input. The keyboard detection is functioning properly, however, the redirect functionality seems to be failing. The complete code can be found on GitHub (even thou ...

The element 'x' is implicitly bound with a type of 'any'

I've been exploring the world of Nextjs and TypeScript in an attempt to create a Navbar based on a tutorial I found (). Although I've managed to get the menu items working locally and have implemented the underline animation that follows the mou ...

When the div element reaches the top of the page, it sticks to the top and is only displayed when the user

In the center of a full-screen hero section, there is a form. When it reaches the top, its position becomes fixed and additional classes are added through a script - such as shrinking its height and adding a background. What I aim to achieve is for the fo ...

Determining the Validity of a Date String in JavaScript

I encountered an issue while attempting to validate a date string using the following code: const isValidDate = (date: any) => { return (new Date(date) !== "Invalid Date") && !isNaN(new Date(date)); } For instance: let dateStr = "some-random-s ...

Simultaneously activate the top and bottom stacked components by clicking on them

One of my components has two child components, A and B. Component A is set to position: absolute and placed on top of component B like an overlay. Additionally, component A has a higher z-index. Both components have onClick events attached to them. My que ...

Spinning Loader in ui-select AngularJS

Currently, I am working with AngularJs and the ui-select plugin from ui-select. My goal is to implement a spinner while fetching data from the server. How can I integrate a spinner directly into the HTML code? The following snippet shows the existing HTML ...

Optimizing the performance of "document.createElement"

When attempting to display multiple rows of data in a popup using a for loop, I initially utilized text strings to create and append the div elements. However, I discovered that using document.createElement resulted in a 20% improvement in performance. D ...

`Loading CSS and JS files in node.js: A step-by-step guide`

I've searched through numerous similar questions without success, so I'm reaching out for help. My folder structure looks like this: Source Code Frontend Graphs.html Graphs.css Temperature.js Server_Backend server.js I aim ...

Arranging the items in a specific sequence - Angular

I am dealing with an object of objects and I need to display these objects and their values in a specific order (not alphabetically). How can I accomplish this using angular? Below is a sample of my object: var filters = { language : { someProperty : ...

Having difficulty with collapsing Bootstrap side navigation menu levels

I've been searching high and low for an example that matches my current issue, but so far, no luck. I'm attempting to design a collapsible side navigation with multiple levels in bootstrap using bootstrap.js. The problem I'm facing is that ...

Implementing conditional text display in React.js

Just starting out with React I am attempting to display a basic text only after logging in based on a condition in my React Redux component, but no matter what I do, the text always shows up. The login functionality is working correctly and I am able to ...

Why won't my AngularJS Google Maps marker trigger any events?

My issue is with the marker event not working on a UI Google Map. I am using this link. Here is my view setup: <ui-gmap-markers models="mapResult" fit="true" idkey="mapResult.id" coords="'form_geo'" click="'onclick'" events="mapRe ...

Guide to storing a PDF document in a MYSQL database using PHP

I am attempting to save all the input information provided by the user in a database. Everything gets saved successfully except for the PDF file. public function insertUM() { if($_POST['um-area']) { $this->usermanual = ...

Encountering an error while populating the Google Charts API with data: "The column header row need to be in array format."

Is there a way to populate a Google Chart with data from a function? I'm encountering an issue where I define the header row but receive an error message saying "Column header row must be an array." How can I resolve this problem? Below is the code sn ...

JQuery script is malfunctioning

My community website is set up as shown below: <div id="posts"> <div class="container"> <div id="placeholder"></div> <h1>Friend Requests</h1> </div> </div> getRequests.js appends the ...

The margin on the right side is not functioning as expected and exceeds the boundary, even though the container is using the flex display property

I'm struggling to position the rating stars on the right side without them going outside of the block. I attempted using 'display: flex' on the parent element, but it didn't solve the issue(( Currently trying to adjust the layout of t ...

Obtain every possible sequence of US phone number segments for a provided number

The format of a US phone number is as follows: (XXX) XXX-XXXX Given a string consisting only of digits with a length between 0 and 10, I want to generate an array of all possible chunks that match the US phone number format. For example: Input: "54" Out ...

Express.js and Multer are facing an issue where the response is being sent before the onFileUploadComplete function is

Currently, I am utilizing the following code for a file upload service: onFileUploadStart: function (file) { uploadPath = ""; imageDimensions = null; console.log(file.originalname + ' is starting to upload...'); }, on ...