Forums

Open links in new tab (1 post)

  1. gideonstrumpet
    Member
    Posted 4 years ago #

    Hello all. Thanks in advance for any help.

    I want to add the option of opening links in a new tab/window, leaving it up to readers to decide what they want to do.

    I've found code that seems to work, but have no idea where to put it in WordPress.

    From this site:

    If you want to add this feature to your Web site, use the following code. It is customary (though not mandatory) to put it in the <head> of your page:
    
    <script language="JavaScript"><!--
    	// thanks to randomwalks.com for this code
    	function targetLinks(boNew) {
    		if (boNew)
    			where = "_blank";
    		else
    			where = "_self";
    		for (var i=0; i<=(document.links.length-1); i++) {
    			document.links[i].target = where;
    		}
    	}
    	// -->
    </script>
    
    Use this code in the <body> of your page, wherever you want the checkbox to appear:
    
    <form name="targeter">
    <input type="checkbox" name="targetbox" id="tcheck"
        onclick="targetLinks(this.checked);">
    <label for="tcheck" style="cursor: hand;">
        links open windows
    </label>
    </form>

    So where do I insert this code such that it shows up after the <head> tag and <body> tag respectively?

    Any help would be appreciated.

    It is implemented on a WP blog here and seems to work well.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by gideonstrumpet
  • This topic is not resolved
  • WordPress version: 2.5.1

Tags

No tags yet.