A way to open a set of links in new tabs automatically

Discussion in 'Javascript' started by spx2, Sep 20, 2009.

  1. spx2

    spx2 Guest

    Hi,

    I'm writing on a project where I'd need to open a set of links on the
    page automatically in new tabs.
    So I don't want to change the target attribute of the link to open in
    a new tab, but actually open the link
    in a new tab.
    I'll be using Opera and Firefox for the application.
    Is there any way that I can make this work ?
    I see in previous versions it was possible to generate an click event
    and dispatch it to the link,
    but not sure if this is still possible with current implementations of
    Firefox due to security concerns ?
    I'm really looking forward to your oppinions on this
     
    spx2, Sep 20, 2009
    #1
    1. Advertising

  2. spx2

    Evertjan. Guest

    spx2 wrote on 20 sep 2009 in comp.lang.javascript:
    > I'm writing on a project where I'd need to open a set of links on the
    > page automatically in new tabs.


    The choice between tabs and new pages is not accessable from the page's
    script in most if not all tab-ready browsers.

    > So I don't want to change the target attribute of the link to open in
    > a new tab,
    > but actually open the link in a new tab.


    =======================================
    var theURL = '/myFolder/myUrlNr';
    var numberOfUrls = 17; // myUrlNr0 to myUrlNr16
    for (i=0;i<numberOfUrls;i++)
    window.open(theUrl+i+'.html','_blank');
    =======================================

    They could open in new windows, if the browser is not set to open in tabs.

    > I'll be using Opera and Firefox for the application.
    > Is there any way that I can make this work ?


    Please make yourself more clear.

    > I see in previous versions it was possible to generate an click event
    > and dispatch it to the link,


    You cannot "dispatch [something] to [a] link"
    Ah, you mean dispath it to the other tabs/windows?
    If they are in the sme domain, you can:

    =======================================
    var theURL = '/myFolder/myUrlNr';
    var numberOfUrls = 17; // myUrlNr0 to myUrlNr16
    for (i=0;i<numberOfUrls;i++)
    window.open(theUrl+i+'.html','windoNr'+i);

    ....

    <span onclick =
    "windoNr5.document.getElementById('div1').innerHTML = 'foo<br>bar';"
    >click Me</span>


    =======================================

    not tested!

    > but not sure if this is still possible with current implementations of
    > Firefox due to security concerns ?


    Crossdomain security reasons,
    leaving someone's concerns for what they are.

    > I'm really looking forward to your oppinions on this


    It would be too bad if you couldn't care less. ;-)

    [please use a name or nickname and a signature]

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 20, 2009
    #2
    1. Advertising

  3. spx2 wrote:
    > I'm writing on a project where I'd need to open a set of links on the
    > page automatically in new tabs.


    I don't think you need that.

    > So I don't want to change the target attribute of the link to open in
    > a new tab, but actually open the link
    > in a new tab.


    What about users with clients without client-side script support?

    > I'll be using Opera and Firefox for the application.


    Which versions on which operating systems?

    > Is there any way that I can make this work ?
    > I see in previous versions it was possible to generate an click event
    > and dispatch it to the link,


    Really? How?

    > but not sure if this is still possible with current implementations of
    > Firefox due to security concerns ?


    You mean _versions_, not implementations. And why don't you simply try the
    solution that once worked with the newer versions?

    > I'm really looking forward to your oppinions on this


    <http://jibbering.com/faq/#posting>
    <http://www.catb.org/~esr/faqs/smart-questions.html>


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Sep 20, 2009
    #3
  4. spx2

    Evertjan. Guest

    Hans-Georg Michna wrote on 20 sep 2009 in comp.lang.javascript:

    > On 20 Sep 2009 08:12:41 GMT, Evertjan. wrote:
    >
    >>window.open(theUrl+i+'.html','_blank');

    >
    > Usually triggers a popup warning dialog on newer browsers,
    > unfortunately.


    No it does not "usually", it depends on the settings,
    and on the ideas of the browser programmers.

    I don't have set such constraints.

    The OP wrote:
    >>> I'll be using Opera and Firefox for the application.


    So it is not open to the general public, [they use IE, even IE6 and Chrome
    and Safari too, remember] so he can tell the users to set the browser
    othrerwize.

    No, there is no way you can circumvent my browser settings,
    and that is a good thing.

    > I've been looking for a solution to this as well,


    Most of us here are happy and know that such looking is useless.

    > just on my own
    > computer. Currently use an AutoIt script, which is a rather
    > crude method.
    >
    > I doubt that it would work on most browsers over which you have
    > no control, because of the popup blockers. It would be a
    > spammer's dream if this worked. They'd love to fill your tabs
    > with their garbage.


    Indeed, but the OQ suggests a controlled browser environment.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 20, 2009
    #4
  5. On Sep 20, 3:12 am, "Evertjan." <> wrote:
    > spx2 wrote on 20 sep 2009 in comp.lang.javascript:
    >
    > > I'm writing on a project where I'd need to open a set of links on the
    > > page automatically in new tabs.

    >
    > The choice between tabs and new pages is not accessable from the page's
    > script in most if not all tab-ready browsers.
    >
    > > So I don't want to change the target attribute of the link to open in
    > > a new tab,
    > > but actually open the link in a new tab.

    >
    > =======================================
    > var theURL = '/myFolder/myUrlNr';
    > var numberOfUrls = 17; // myUrlNr0 to myUrlNr16
    > for (i=0;i<numberOfUrls;i++)
    >    window.open(theUrl+i+'.html','_blank');
    > =======================================
    >
    > They could open in new windows, if the browser is not set to open in tabs..
    >
    > > I'll be using Opera and Firefox for the application.
    > > Is there any way that I can make this work ?

    >
    > Please make yourself more clear.
    >
    > > I see in previous versions it was possible to generate an click event
    > > and dispatch it to the link,

    >
    > You cannot "dispatch [something] to [a] link"
    > Ah, you mean dispath it to the other tabs/windows?
    > If they are in the sme domain, you can:
    >
    > =======================================
    > var theURL = '/myFolder/myUrlNr';
    > var numberOfUrls = 17; // myUrlNr0 to myUrlNr16
    > for (i=0;i<numberOfUrls;i++)
    >    window.open(theUrl+i+'.html','windoNr'+i);
    >
    > ...
    >
    > <span onclick =
    > "windoNr5.document.getElementById('div1').innerHTML = 'foo<br>bar';"
    >
    > >click Me</span>

    >
    > =======================================
    >
    > not tested!
    >
    > > but not sure if this is still possible with current implementations of
    > > Firefox due to security concerns ?

    >
    > Crossdomain security reasons,
    > leaving someone's concerns for what they are.
    >
    > > I'm really looking forward to your oppinions on this

    >
    > It would be too bad if you couldn't care less. ;-)
    >
    > [please use a name or nickname and a signature]
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)


    Ok, so thanks a lot for taking the time to write this :)
    I've used the second piece of code , and I'm opening up some links
    and saving the returned Window reference objects in openedWindows
    (in order to know what to close from the close_links_new_tabs button
    later).
    Also, after opening the windows up I'd like to re-focuse on the
    initial window.
    And I'm doing window.focus() , and it doesn't work.
    I've checked that was the real window I wanted by trying to see the
    title of the window.
    So it's a bit weird that the last opened window is focused and at the
    same time,
    when I print window.document.title what I see is the title on which
    the open_links_new_tabs
    button was...
    I've also tried to store the window object before the .each call
    (which is actually a for loop)
    and apply .focus to that and it still does not focus.

    289 $("#open_links_new_tabs").click(function(){
    290 // opens the links in the items in new
    tabs
    291 var i = 0;
    292 $(".table_row > td > a").each(function() {
    293 i++;
    294 openedWindows.push(
    295 window.open($(this).attr
    ('href'),'opened_link'+i)
    296 );
    297 //alert($(this).html());
    298 });
    299 window.focus();
    300 });
    301
    302 $("#close_links_new_tabs").click(function(){
    303 $(openedWindows).each(function(idx,obj)
    { obj.close() });
    304 });

    Maybe you have a suggestion related to this ?

    Thanks,
    Stefan
     
    Stefan Petrea, Sep 22, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qwweeeit
    Replies:
    2
    Views:
    660
    qwweeeit
    Dec 14, 2005
  2. tap@murphy's.place.com

    Having a problem with links and tabs in IE

    tap@murphy's.place.com, May 9, 2008, in forum: HTML
    Replies:
    1
    Views:
    369
  3. John Devlon
    Replies:
    2
    Views:
    466
    Gregory A. Beamer
    Dec 7, 2009
  4. rantingrick

    Tabs -vs- Spaces: Tabs should have won.

    rantingrick, Jul 16, 2011, in forum: Python
    Replies:
    95
    Views:
    1,887
    Roy Smith
    Jul 19, 2011
  5. John Kopanas
    Replies:
    2
    Views:
    302
    Gregory Brown
    Jan 29, 2007
Loading...

Share This Page