SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    522
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Simulate middle button click

    I'm trying to force a link to open in a new tab - is this possible? If I use the target=blank attribute then the default behaviour in most browsers is to open in a new window, so I'm trying to simulate a middle click (this is for an internal page so I'm not too bothered about annoying browsers).

    I thought if I capture a left click event and modify the 'which' attribute, then re-trigger the event, this might work:

    Code:
    $('#mylink').click(function(e){
    		if(e.which==1) e.preventDefault();
    		e.which=2;
    		$('#mylink').trigger( e );
    	});
    But nothing happens. Is it even possible? Any suggestions as to how to do it?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by hessodreamy View Post
    I'm trying to force a link to open in a new tab - is this possible?
    No, it is not possible to use JavaScript to tell a web browser to open a new page as a tab.
    That is something that the individual web browser settings dictate, according to the user's desired setting.

    For example: see the Firefox options window - tab settings
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •