Go Back   Dynamic Drive Forums > General Coding > JavaScript
Search Dynamic Drive Forums:

Closed Thread
 
Thread Tools Search this Thread
  #1  
Old 04-18-2007, 01:59 PM
Raj Raj is offline
Junior Coders
 
Join Date: Apr 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Angry How to Open links in New Tab of browser with Javascript or VBscript

I have tried a lot but couldnot find any script which can help me open my links from an html page in a NEW TAB of browsers (IE7 or Firefox).

Can some one help me?
  #2  
Old 04-18-2007, 02:08 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,001
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

That behavior is configured by the user and, as far as I know, only by the user.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
  #3  
Old 04-18-2007, 02:16 PM
Raj Raj is offline
Junior Coders
 
Join Date: Apr 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks John..... but there has to be a way with some kind of script....
  #4  
Old 04-18-2007, 02:21 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,001
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

Not really, many things about the browsing experience are solely under the control of the user. Javascript and other coding languages can enhance the browsing experience but, they cannot take over the browser except in the cases of Java and Active X. These coding languages allow the programmer to take control of the user's computer but, there are safeguards to prevent this and so, they often do not achieve their objectives.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
  #5  
Old 04-18-2007, 02:28 PM
Raj Raj is offline
Junior Coders
 
Join Date: Apr 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there any way through which we can trigger keyboard short cut with a click of a mouse. Eg: activate "ctrl+t" with a click on a link ?

Last edited by Raj; 04-18-2007 at 02:46 PM.
  #6  
Old 04-18-2007, 04:40 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,001
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

Perhaps, but I really don't think so. You used to be able to create a new event object:

var ev=new Event()

and assign its type and other property values, we would use (if we could still do this):

ev.type=keydown
ev.keyCode=17

Then we could fire it with an onclick event of a link but, even if this were still allowed, I have no idea if it would work.

The reason this whole thing is so tricky is that as far as javascript is concerned, opening a link in a new tab is the same thing as opening one in a new window. It just depends upon how the user has their browser configured.

That and the fact that javascript doesn't really create anything that is usually user initiated, it just reacts to things that the user does and/or manipulates styles, content, and layout.

Finally, what would be so bad about just opening a new window? For users that have their browsers configured to open new windows in tabs, they will get a tab, others will get a new browser instance. What could be so important about your content that it just has to be in a tab? Also, even if this could be done, some browsers surly could override it and tab-less browsers could not comply.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
  #7  
Old 04-18-2007, 04:48 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,001
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

I may be over thinking this. Just use:

HTML Code:
<a href="some.htm" target="_blank">Link Text</a>
That's, I believe, the best you can do.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
  #8  
Old 04-18-2007, 05:25 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,001
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

OK, here's another idea, get the user to do it:

HTML Code:
<a href="some.htm" onclick="if(!event.ctrlKey&&!window.opera){alert('Please Try Again while holding down the Ctrl Key');return false;}else{return true;}" target="_blank">Link Text</a>
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
  #9  
Old 04-19-2007, 08:08 AM
Raj Raj is offline
Junior Coders
 
Join Date: Apr 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi John, I tried your idea of handling the even. I was able to alert the values but could not Fire an event.

Here is the code:

<html>
<head>
<script type="text/javascript">
function foo(elem, evt){
/*alert(
[
"elem : " + elem.nodeName,
"shiftKey : " + evt.shiftKey,
"keyCode : " + evt.keyCode
].join("\n")
);
*/

evt.ctrlKey=true;
evt.keyCode=17;
event.srcElement.fireEvent("onclick",evt);

}
</script>

</head>
<body>
<A href="#" onclick="foo(this, event)" onkeypress="foo(this, event)">test</A>
</body>
</html>

Any idea what I doing wrong?
  #10  
Old 04-19-2007, 03:46 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,001
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
Default

The ctrlKey property is only a getter so, no matter what else may or may not be wrong with your code, you cannot set the ctrlKey property of an event as it appears that you are trying to do. I'm not certain but the keyCode property may also be only a getter. If it isn't, and is also a setter, it still may not be able to influence what the browser does as, event results set by javascript have no particular claim on controlling browser behavior although, they often do have that effect.

Using:

event.srcElement

is for IE only.

There could also be other problems.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:14 AM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.