如何从后台发送消息到内容脚本?

时间:2016-07-15 05:43:04

标签: javascript jquery google-chrome-extension

我正在从后台发送消息到内容脚本。 我的background.js

For Each gvr As TableRow In TabelVerificari.Rows

            For i = 1 To TabelVerificari.Rows.Count - 1

                Idx = "P" & i
                Dim Result1 As TextBox = gvr.FindControl("BOX_Component" & "_" & Col & i)
                Dim Result2 As TextBox = gvr.FindControl("BOX_Drowing" & "_" & Col & i)
                Dim Result3 As TextBox = gvr.FindControl("BOX_PartNo" & "_" & Col & i)
                Dim Result4 As TextBox = gvr.FindControl("BOX_BatchNo" & "_" & Col & i)
                Dim Result5 As TextBox = gvr.FindControl("BOX_Amount" & "_" & Col & i)
                Dim Result6 As TextBox = gvr.FindControl("BOX_Comments" & "_" & Col & i)

                Component = Result1.Text
                Drawing = Result2.Text
                PartNo = Result3.Text
                batchNo = Result4.Text
                Amount = Result5.Text
                Comments = Result6.Text

                Dim InsertBOM As SqlConnection = Nothing
                InsertBOM = FunctionConnection()
                Dim cmdBOM As SqlCommand = New SqlCommand()

                Try
                    'Insert Function 
                    cmdBOM.Connection = InsertBOM
                    cmdBOM.CommandTimeout = 50
                    cmdBOM.CommandType = System.Data.CommandType.StoredProcedure
                    cmdBOM.CommandText = "InsertIroBOMParts"

                    cmdBOM.Parameters.AddWithValue("@OrderID", OrderID)
                    cmdBOM.Parameters.AddWithValue("@OrderSelection", i)
                    cmdBOM.Parameters.AddWithValue("@Idx", Idx)
                    cmdBOM.Parameters.AddWithValue("@Component", Component)
                    cmdBOM.Parameters.AddWithValue("@DrawingNo", Drawing)
                    cmdBOM.Parameters.AddWithValue("@PartNo", PartNo)
                    cmdBOM.Parameters.AddWithValue("@BatchNoParts", batchNo)
                    cmdBOM.Parameters.AddWithValue("@Amount", Amount)
                    cmdBOM.Parameters.AddWithValue("@Comments", Comments)

                    InsertBOM.Open()
                    cmdBOM.ExecuteNonQuery()

                Catch ex As Exception
                    LBL_Error.Text = "Please complete correctly boxes!"
                    Exit Sub
                Finally

                    If InsertBOM.State = ConnectionState.Open Then
                        InsertBOM.Close()
                    End If
                    'Session("OrderNo") = OrderID
                    'Response.Redirect("MV_UpdateSample.aspx")
                End Try

            Next
            Exit For
        Next

我的content-script.js

chrome.runtime.onMessage.addListener(
 function(request, sender, sendResponse) {
  switch(request.type){
    case "login-check":
     checkLogin();
    break;
  }
});

function checkLogin() {
 // var test = localStorage.getItem("test");
 // alert(test);
 chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ 
  chrome.tabs.sendMessage(tabs[0].id, {type: "login"}, function(response) {
   console.log(response.farewell);
   //alert(response.farewell);
  }); 
 });
}

它向我显示错误“(未知)事件处理程序中的错误:TypeError:无法读取未定义的属性'告别' ”。 我已经尝试了所有方法,但它没有用,请帮忙。 提前谢谢

0 个答案:

没有答案