Able to Define Target Frame for all Hyperlinks?

This forum is for all Flare issues related to styles, stylesheets and XML.
Post Reply
techwriter31
Propellus Maximus
Posts: 551
Joined: Wed Mar 05, 2008 10:50 am

Able to Define Target Frame for all Hyperlinks?

Post by techwriter31 »

For our online help hyperlinks, we'd like to always launch a new window/browser tab. Is it possible to globally define the Target Frame behavior for hyperlinks (within the "a" hyperlink style in our stylesheet or similar), rather than for each individual link?
Kellie
NorthEast
Master Propellus Maximus
Posts: 6426
Joined: Mon Mar 05, 2007 8:33 am

Re: Able to Define Target Frame for all Hyperlinks?

Post by NorthEast »

You couldn't do this using CSS, but it's easy enough to do using a script.

The following jQuery example should work for HTML5 outputs.

Code: Select all

	$(document).ready(function() {
		$( 'a' ).attr( 'target','_blank' );
	});
This will open all links in a new window.
Mind, opening all links in a new window could be incredibly annoying for the user - or is there a reason to do so?
If you just wanted external links to open in a new window, you'd replace $('a') with something like $( 'a[href^="http://"]' )

If you want to apply this to all topics, either include it straight in the master page, or put it in a separate file which is linked to the master page.

If you want this for WebHelp (which doesn't include jQuery), then it's probably not worth including jQuery just for this; but I'm sure there are plenty of plain javascript examples available if you search on Google.
techwriter31
Propellus Maximus
Posts: 551
Joined: Wed Mar 05, 2008 10:50 am

Re: Able to Define Target Frame for all Hyperlinks?

Post by techwriter31 »

Thanks Dave!

Oops, I should have specified that we're using HTML5 for this website! :)
Dave Lee wrote:This will open all links in a new window.
Mind, opening all links in a new window could be incredibly annoying for the user - or is there a reason to do so?
Yeah, I agree that typically opening all links in a new window could be annoying. In this case, we're creating a Knowledge Base website with no interlinking between help topics, and only external linking to additional resources - either via our company website or partner websites. However, this may not always be the case and it definitely makes sense to use the $( 'a[href^="http://"]' ) method.

Thanks again!
Kellie
NorthEast
Master Propellus Maximus
Posts: 6426
Joined: Mon Mar 05, 2007 8:33 am

Re: Able to Define Target Frame for all Hyperlinks?

Post by NorthEast »

Yep, that should work.
Thinking about it, probably better to use $( 'a[href^="http"]' ) - as you may have some https links too.
deeptikorwar
Sr. Propeller Head
Posts: 111
Joined: Tue Aug 20, 2013 11:38 pm

Re: Able to Define Target Frame for all Hyperlinks?

Post by deeptikorwar »

Hi Dave,

Using the JQuery code is it possible to achieve the following?
1. Open hyperlinks, xrefs in new window only when the hyperlink or xref is not within the same topic
2. Open external references in a new window always

We mostly have procedures and the user would want the current topic open when he is looking for additional information.

If the above is not possible using a JQuery, is it possible to set this within the stylesheet so that the default behaviour would be to open in new window and only when I am creating a link in the same topic, I can manually change the style?

Thanks,
Deepti
NorthEast
Master Propellus Maximus
Posts: 6426
Joined: Mon Mar 05, 2007 8:33 am

Re: Able to Define Target Frame for all Hyperlinks?

Post by NorthEast »

For 1, you could perhaps do this by checking for links that end with ".htm", as this should match links to other topics, but not links within the topics (bookmarks, drop-downs, etc.):

Code: Select all

$( 'a[href$=".htm"]' ).attr( 'target','_blank' );
For 2, just use the example in the previous post:

Code: Select all

$( 'a[href^="http"]' ).attr( 'target','_blank' );
Post Reply