0

I am trying to load URL from server side and the url is an API that sends SMS.

My problem is I need to load the url but that should not open a page or any window when that is triggered.

string url = "http://xxxxx.xxxxx.com/api/sendmsg.php?user=xxxx&pass=xxxx&sender=xxx&phone=xxxxxxxxxxx&text=this%20is%20test%20sms&priority=ndnd&stype=normal";
string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
Microsoft DN
  • 9,706
  • 10
  • 51
  • 71
Shaik
  • 930
  • 1
  • 20
  • 48
  • Not sure how it is set up. But read about Ajax. It might help. Here are some [examples](http://api.jquery.com/jquery.ajax/) – Andrey Borisko Nov 23 '15 at 13:49

4 Answers4

3

Well, you could send an ajax GET request from the client, although I don't understand why you are not calling this URL from the server side instead.

This would be server side:

using(WebClient client = new WebClient ())
{
    string url = "http://xxxxx.xxxxx.com/api/sendmsg.php?user=xxxx&pass=xxxx&sender=xxx&phone=xxxxxxxxxxx&text=this%20is%20test%20sms&priority=ndnd&stype=normal";
    client.DownloadString(url);
}

If you choose do it on client side, you can use this code:

string url = "http://xxxxx.xxxxx.com/api/sendmsg.php?user=xxxx&pass=xxxx&sender=xxx&phone=xxxxxxxxxxx&text=this%20is%20test%20sms&priority=ndnd&stype=normal";
string s = "var xmlHttp = new XMLHttpRequest();";
s += "xmlHttp.open('GET'," + url + ", false);";
s += "xmlHttp.send(null);";

ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
laszlokiss88
  • 4,001
  • 3
  • 20
  • 26
0

instead of using window.open, You can use iframe with display:none and then change url of this iframe.

Please find the code below.

Using RegisterStartupScript

ASPX

<div ID="myCustomDiv"></div>

<script type="text/javascript">
    function updateDiv(content) {
        document.getElementById("myCustomDiv").innerHTML = content;
    }
</script>

Code behind

protected void Page_Load(object sender, EventArgs e)
{
    string url = "updateDiv(\"<iframe style='display:none' src='http://stackoverflow.com'></iframe>\");";

        ClientScript.RegisterStartupScript(this.GetType(), "script", url, true);
    }

Another approach during pageload

ASPX

<div runat="server" ID="myCustomDiv"></div>

Code behind

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        string iframeString = "<iframe style=\"display:none\" src=\"http://stackoverflow.com\"></iframe>";

            myCustomDiv.InnerHtml=iframeString;
        }
    }
Avinash Jain
  • 7,200
  • 2
  • 26
  • 40
0

If you want it to open in the current window, then replace the 'popup_window' with '_self'

w33z33
  • 378
  • 2
  • 17
0

There's a whole slew of ways to accomplish this task:

  1. Use AJAX to send a GET or POST request to this URL. This is easily done via the regular browser api or via JQuery.

  2. You can load an iframe which is set to have minimal width/height, or just no display.

  3. You could just add an img tag to the page, with the src attribute set to the url of your API. If you use this option, then it would be best to find a way to hide the image not found icon.

The browser is designed to send requests, so it has many ways to do so, all of which will have their own properties and trade-offs. I recommend looking into the many ways to accomplish this and choose which best fits your particular use case. Good luck!

Community
  • 1
  • 1
cmcquillan
  • 696
  • 4
  • 12