Why when window.open(url) called directly from input botton bypasses popblockers but when called through another function gets blocked

Why when the javascript window.open(url) function is called directly from an input botton, it  bypasses popblockers but when called through another function it gets blocked?

See the code attached.
Test1 button is via a function that first uses pagemethods to process the string for the address. I need to use a server side function (The pagemethod works perfect, it is not an issue) The fact that is called inderectly somehow alerts the popup blockers.
Test2 button has the url string in it.
Safari, Firefox, Chrome, Opera and IE will open a second window when using button 2 with no problems even with blockers ON.

Only IE will open with button 1, Firefox, Chrome and Opera will advise that the action was blocked and allow override. Safari will provide no clue that the call is been blocked.

I need for button 1 to behave like button 2.
Any help will be appreciated. Please any solution if posible in vb.
Thank you.



<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="jsserverfnvb._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager" runat="server"
       EnablePageMethods="true"></asp:ScriptManager>
<script language="javascript" type="text/javascript">
    function MyMethod_Result(ResultString) {
        var urlmap = 'http:\/\/www.bing.com/maps/?v=' + ResultString;
        window.open(urlmap);
    }

    function CallMyMethod() {
        PageMethods.MyMethod("World", MyMethod_Result);
    }
</script>

<input id="test1" type="button" value="Test via server" name="test1" onclick ="CallMyMethod()" />
<input id="test2" type="button" value="Test Direct" name="test2" onclick ="window.open('http:\/\/www.bing.com/maps/?v='+'6.2&mkt=fr-FR')" />
   
    
    </form>
</body>
</html>


Imports System.Web.Services
Partial Public Class _Default
    Inherits System.Web.UI.Page

    <WebMethod()> _
    <Script.Services.ScriptMethod()> _
    Public Shared Function MyMethod(ByVal name As String) As String
        Return "6.2&mkt=fr-FR"
    End Function
End Class

Open in new window

IvicarpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Hello Ivicarp,

The first one can be considered as unsolicited and the other one solicited by the user.

Regards.
0
leakim971PluritechnicianCommented:
The new browser generation want to protect the user
0
IvicarpAuthor Commented:
leakim971 thanks for your reply. What makes window.open to behave differently? I use all five major browser with the latest versions. Still no explanation of why the same function allows in all of the browser to open up a tab or new window when url is passed as a string but not as a variable.
I checked also with ASP buttons thinking that perhaps the trip to the server (postback) was the culprit.
After testing more than a week, the conclusion I have is that if passing the url via a string it does not block, if you pass it via a variable it makes the blocker to work. WHY??


0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

IvicarpAuthor Commented:
I did more testing and I am changing my opinion, I believe now that it has to do with a postback issue.
If somebody could confirm this, I would hate to translate to a client function the preparation of the string for the URL for it not to work later on.
0
Gagan_JauraCommented:
Refer to the following links. These will help.
http://msdn.microsoft.com/en-us/library/ms537632(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms536753(v=VS.85).aspx

Also, you can modify your code as below.
<script language="javascript" type="text/javascript">
    function MyMethod_Result(ResultString) {
        var urlmap = 'http:\/\/www.bing.com/maps/?v=' + ResultString;
        var result = window.open(urlmap);
        writeTo(result);
    }
    function CallMyMethod() {
        PageMethods.MyMethod("World", MyMethod_Result);
    }
    function writeTo(w) {
        w.document.write('Test');
     }
</script>

0
Gagan_JauraCommented:
If the above solution does not work then you have no option but to create a custom popup. Use below given link, it has the code to create a custom popup. This site shows you the sample also.
http://www.dynamicdrive.com/dynamici...htmlwindow.htm
0
IvicarpAuthor Commented:
Gagan thank you for your replies.
On the following line for some reason that I dont understand,  result ends with a null value even though urlmap has the proper value in it

var result = window.open(urlmap);
Please advice
Thanks
0
IvicarpAuthor Commented:
Gagan:
The link provided has a typo, I tried to find the proper page but couldnt.
If you would be kind enogh, thanks.

http://www.dynamicdrive.com/dynamici...htmlwindow.htm
0
Gagan_JauraCommented:
It is returning null because the popup is blocked. If you go through the msdn links that I have provided in my earlier answers, you can figure out the reason of returning null. You can try setTimeout() method (the second msdn link).
Sorry for the typo, below is the actual link
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow.htm
Please let me know if it solves your problem
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IvicarpAuthor Commented:
Gagan:

I had to convert my codebehind function to client javascript, get the database data required and load on hidden variables at onload, once the input button was pressed, then verify my checkboxes on aspx to see which hidden variables I had to use and prepare the string on the client side and finally use window.open. By doing all of these i managed to avoid  a postback and got the button to bypass the popup blockers on all major browser.
Thank you all. Gagan I am giving you the points. Your proposal open my eyes to find the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.