Results 1 to 5 of 5

Thread: Force a web page to open in new window/tab???

  1. #1
    Join Date
    Dec 2012
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Force a web page to open in new window/tab???

    Okay, so we all know how to make a hyperlink open in a new window or new tab but...

    I have built a website with several pages. But now I would like one particular page to always open in a new window or tab. Can i put something in the coding of this particular page to make it open in a new window or do I really have to go in to every page and amend all the links to this page?

    Imagine if I had several hundred pages with thousands of links to this one page, would I really have to change all these links? Please tell me that it isn't so!!

    Help!

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    You can put <base target="_blank"> in the head section of the page.
    Eddy Proca
    I love Dropbox. Get it through my girlfriend's referral link (I reached my limit) and both you and her get 500 MB extra! Thanks and you're welcome!

  3. #3
    Join Date
    Dec 2012
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    This would make all links (as default) within that page open in a new tab. Unfortunately not what I am after but thanks.

    I have a fully functioning website, functioning ok as it is. Every page opens within the same window. But i now need just one specific page 'example.html' to always open in a new tab/window. There is at least one link to this page on every web page. I want this page ONLY to open in a new tab or window. Can I achieve this without going through the whole website and manually changing every link to this page?

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,982
    Thanks
    16
    Thanked 311 Times in 309 Posts
    Blog Entries
    11

    Default

    You said in your first post that you have several pages on your website - how many is *several*? If there are only 10 or 20, or even 30, its probably going to be a relatively easy fix to edit them all manually. I've had to manually tweak websites with 50+ pages before and once you get into the swing of find-edit-replace, it doesn't really take that long (probably less time than worrying about finding a workaround too)

    If this link forms part of a menu, maybe now would be a good time to think about separating it off as a Server Side Include or php include - it will save you lots of edit-time in future.

    Server Side Include : http://www.javascriptkit.com/howto/ssi.shtml
    PHP include : http://www.tizag.com/phpT/include.php
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,030
    Thanks
    44
    Thanked 3,211 Times in 3,173 Posts
    Blog Entries
    12

    Default

    Not really. You could put a script on each page, it could be external, so you would need only one script and if you already have a script that runs on every page, this could simply be added to it:

    Code:
    ;(function(){
    	var re = /example\.htm[$\?#]/;
    	function targetlink(e){
    		e = e || event;
    		var t = e.target || e.srcElement, href;
    		if(t.href && re.test(href = t.href) || t.parentNode.href && re.test(href = t.parentNode.href)){
    			window.open(href, '_blank')
    			e.preventDefault && e.preventDefault();
    			e.returnValue = false;
    		}
    	}
    	if (document.addEventListener){
    		document.addEventListener('click', targetlink, false);
    	}
    	else if (document.attachEvent){
    		document.attachEvent('onclick', targetlink);
    	}
    })();
    Just change example\.htm$ in the above to the actual name of the page, use the down slash as shown for the . character and the bracketed [$\?#] at the end to indicate the end of the filename.

    Of course this will only work if javascript is enabled. Most (like 99%) people do have that.
    Last edited by jscheuer1; 01-21-2013 at 02:16 PM. Reason: code imprivement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Resolved Force link to download image not open
    By davelf in forum HTML
    Replies: 6
    Last Post: 05-31-2012, 03:17 AM
  2. Accordion Content - Force Header To Stay Open
    By lahue in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 02-21-2011, 06:26 PM
  3. Force URL to open as IFrame in outside URL
    By MJensen in forum JavaScript
    Replies: 80
    Last Post: 01-14-2008, 09:25 PM
  4. Replies: 0
    Last Post: 07-18-2006, 05:17 AM
  5. Replies: 2
    Last Post: 02-20-2005, 08:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •