user2425234
user2425234

Reputation: 67

Cross-Browser compatible opening of a new tab/window (browser)

I'm sure you can help me with this issue:

I recently run into some issues with opening a new tab / pop-up on a php/javascript site.

My current solution is as followed:

<script type="text/javascript">

            function Popup(url) {
                window.open(url);
            }

    </script> 


    <div class="link_box">

        <a class="link_box_link" href="javascript:Popup('http://www.<website>.com')"><website-name></a>

    </div>

However some of my coworkers using IE6-8 can't seem to open the link. Now I hope you can help me finding the best possible and cross-browser compatible solution for opening a new tab or window. Any help or tip would be greatly appreciated!

Upvotes: 0

Views: 3634

Answers (2)

Joum
Joum

Reputation: 3245

Ok, after looking at the comments produced (mine included), I decided that I should sum it up in an answer.

The cross-browser compatible solution is simply this: (with no Javascript)

<a href="http://www.google.com" target="_blank"> LINK TO GOOGLE </a>

Read about it here.

There are a few reasons why this may not work:

  • browser settings;
  • pop-up blockers

About these, there isn't much you can do. Browser settings aren't editable by your script; AFAIK, there isn't a general way to circumvent pop-up blockers (and thank god for that!). Although, there are a few workarounds that do work under specific conditions. Although, as it may be such a frustrating task to account and inquire about all those conditions with a script, my suggestion of using a modal window with an iframe still stands.

NOTE: Actually, using this should not bring that many trouble with pop-up blockers (though still possible). Note that most times pop-up blockers are triggered exactly by detecting client-side scripting to open new windows - being the method you tried possibly one of the first to trigger it.

Upvotes: 6

dominic
dominic

Reputation: 143

You have to manipulate the target like Joum saved in the comment section. Or you simple are using the posible to return false;.

<a class='popup' href='www.websitename.com'>website</a>

$('a.popup').live('click', function(){
    newwindow=window.open($(this).attr('href'),'','height=200,width=150');
    if (window.focus) {newwindow.focus()}
    return false;
});

Upvotes: 0

Related Questions