Site icon Ondexx Help Center

Custom Script: Open Links in New Window

Ondexx has the ability to add Custom Scripts to your Sites. These scripts can serve many different purposes – you can view these under Administration > Site Setting > Custom Scripting. This menu is accessible by users with the “Configure Site” right.

The below script will cause all hyperlinks in your Site to open in a new window by default. This will exclude any in-page links as well. To add this script to your site:

  1. Copy the code below to your clipboard.
  2. Navigate to Administration > Site Settings > Custom Scripting.
  3. Paste the code below in the “Page Header Scripting” section. If there are already scripts in this field, leave them intact, and paste the code below.
  4. Click SAVE to add the script to your site. All hyperlinks will now open in a new tab by default.
/* FORCE LINKS TO OPEN IN A NEW WINDOW (excludes in-page links) */
$(document).ready(function() {
	/* step 1: clean-up */
	$('.component-content a[href=""]').each(function(i) {
		$(this).removeAttr('href');
	});

	/* step 2: add target attribute */
	$('.component-content a:not([target]):not([name]):not([id]):not(.anchorjs-link):not([href*="#"]):not([class*="lazyload"]):not(.btnViewDoc):not(#btnDownloadDoc):not(.btnLocateFile)').each(function(i) {
		$(this).attr('target', '_blank');
	});
});
Exit mobile version