質問

I have a C# WebService with a method that returns a url which I want to open using window.open from JavaScript. I am calling the method via a ScriptManager, but nothing is happening when I call "window.open" (No errors and the window does not open).

The method returns the url just fine and if I put "console.log" inside the return function it is being called as well.

Here is my service:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
    [WebMethod]
    public string GetUrl()
    {
        return "http://google.dk";
    }
}

Here is my html/javascript:

<head runat="server">
    <title></title>
    <script type="text/javascript">
        function OpenUrl() {
            OpenUrlFromService.Service.GetUrl(function (url) {
                window.open(url);
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="smDefault" runat="server">
            <Services>
                <asp:ServiceReference Path="~/Service.asmx" />
            </Services>
        </asp:ScriptManager>

        <a href="#" onclick="OpenUrl();">Link to popup</a>
    </form>
</body>

Here is a link to the project i'm testing on: http://peecee.dk/upload/download/435257

役に立ちましたか?

解決

I have run your code it is working fine.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top