我正在开发移动的Web应用程序,我想从javascript打开SMS编辑器。 下面是我的aspx代码
<a class="redBtn fltrt" href="#" id="lnkBuy" runat="server" onclick="return makePayment()" onserverclick="lnkBuy_Click" rev='12' rel='21'>Buy</a>
和onClick方法
function makePayment()
{
try
{
var res=confirm('Are you sure to continue?');
if(res == true)
{
window.location='sms:+334343434343';
return true;
}
else
{
return false;
}
}
catch(Error)
{
}
}
这里是我要打开SMS编辑器并调用代码背后的代码
protected void lnkBuy_Click(object sender, EventArgs e)
{
//code goes here
}
通过使用此功能,我可以打开SMS编辑器,但无法重定向到代码后面的代码。任何机构都建议我以同样的方式或任何其他方便的方式执行此操作。
提前致谢
答案 0 :(得分:0)
也许您可以通过其他方式执行此操作,首先执行服务器调用,然后将重定向发送到客户端“sms:+334343434343”?
或者,替代使用ASP.NET回调机制,在window.location更改之前向服务器发送AJAX调用。
这取决于你需要做什么服务器端。
答案 1 :(得分:0)
我使用XMLHTTPRequest将调用发送到我的处理页面并编写另一个函数来重定向到本机SMS编辑器调用。
以下是我的代码
function makeoldPayment(courseId,basketId)
{
try
{
var res=confirm('Are you sure to continue?');
if(res == true)
{
var mobNo = document.getElementById('hidMNo').value;
var lerid = document.getElementById('hidLId').value;
var sendDataToServerReq = getXMLHttpRequest();
var newURL = window.location.protocol + "//" + window.location.host + "/Learners/SaveToDB.aspx?cid=1&mbid=123456&bid=43&lid=3;
//alert(newURL)
sendDataToServerReq.open("POST", newURL, false);
sendDataToServerReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8;");
gosms();
sendDataToServerReq.send("mobno="+mobNo+"&lerid="+lerid+"&basketid="+basketId+"&recordid="+courseId);
location.reload();
return false;
}
else
{
return false;
}
}
catch(Error)
{
}
}
function gosms()
{
try
{
window.location='sms:+334343434343';
}
catch(Error)
{
}
}
function getXMLHttpRequest()
{
var httpRequest = null;
// Create the appropriate HttpRequest object for the browser.
if (window.XMLHttpRequest != null){
httpRequest = new window.XMLHttpRequest();
}else if (window.ActiveXObject != null){
// Must be IE, find the right ActiveXObject.
var success = false;
for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
{
try{
httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
success = true;
}
catch (ex)
{}
}
}
if (httpRequest == null){
//alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");
}
return httpRequest;
}
跳这将有助于一些人:)