samhankin
samhankin

Reputation: 93

Calling client side URL from browser without opening new page

I'm trying to create a button that will dial an IP Phone by visiting a URL string:

http://admin:[email protected]/cgi-bin/ConfigManApp.com?Id=34&Command=1&Number=0123456789

When entering directly into the browser, the page returns a 1 and dials the IP phone.

On my website I can create a simple link that when clicked, visits this page in a new window.

Is there any way of visiting this page without the user seeing that it opens?

Upvotes: 3

Views: 30162

Answers (3)

rubo77
rubo77

Reputation: 20827

This javascript will call it in the background without displaying anything:

<script src="javascript">
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "http://admin:[email protected]/cgi-bin/ConfigManApp.com?Id=34&Command=1&Number=0123456789", true);
xhttp.send();
<script>

Sure, it will be still visible in the console if you analyze the site. You could use a server-side script like PHP if you want to call it without trace like:

<?php
$response=file_get_contents("http://admin:[email protected]/cgi-bin/ConfigManApp.com?Id=34&Command=1&Number=0123456789");

Upvotes: 2

Dave
Dave

Reputation: 10924

Sure you can use an AJAX call:

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    var response = xmlhttp.responseText; //if you need to do something with the returned value
  }
}

xmlhttp.open("GET","http://admin:[email protected]/cgi-bin/ConfigManApp.com?Id=34&Command=1&Number=0123456789",true);
xmlhttp.send();

jQuery makes this even easier:

$.get("http://admin:[email protected]/cgi-bin/ConfigManApp.com?Id=34&Command=1&Number=0123456789")

Edit: since you are traveling across domains and can't use CORS, you can open the link using javascript and them immediately close the window. Example below:

document.getElementById("target").onclick = function(e) {
    var wnd = window.open("http://admin:[email protected]/cgi-bin/ConfigManApp.com?Id=34&Command=1&Number=0123456789");
    wnd.close();
    e.preventDefault();
};

Upvotes: 8

Travis J
Travis J

Reputation: 82267

You would use an XMLHttpRequest

function dialResponse() {
 console.log(this.responseText);//should be return value of 1
}

var oReq = new XMLHttpRequest();
oReq.onload = dialResponse;
oReq.open("get", "http://admin:[email protected]/cgi-bin/ConfigManApp.com?Id=34&Command=1&Number=0123456789", true);
oReq.send();

This will be semi-hidden. However, it is still issued client side so they will see it occur in the network record. If you want this to be truly hidden, you would have to do it server side.

Upvotes: 2

Related Questions