浏览器标签之间的通信,Javascript

时间:2015-04-02 11:24:07

标签: javascript tabs communication

我正在设计这个基于网络的生产管理软件,其中包括客户,产品和订单数据库。我试图完成以下功能。

当用户想要为系统创建新订单时,应该有两种方法。

第一种方式。用户可以先导航到"搜索客户" -page,当他找到合适的用户时,他可以点击一个按钮"为该客户创建新订单"或类似的东西。

然后打开"添加订单" -page,其中包含有关客户的信息。

在此页面上,如果用户点击按钮"添加产品",则应在新标签页中打开"搜索产品" -page。

然后,用户可以添加产品到"添加订单" - 在后台标签中打开的页面,然后点击“说”"添加此产品"按钮。

当用户关闭"搜索产品" -page时,产品将在那里等待"添加订单" -page。

第二条路线。用户可以直接进入"搜索产品" -page,当他点击相同的"添加此产品"按钮,一种空白"添加订单" -page应该使用新添加的产品信息打开后台选项卡。

然后用户可以再次继续添加产品,直到他完成。

如何通过"添加订单" -page和"搜索依赖于发起人的产品" -page之间的双向互动来完成此类操作?我应该使用cookies,ajax还是某种父母,孩子的关系以及搞乱window.opener?

我试图通过以下方式实现这一目标,但它不起作用。



// code in the "search for products"-page

var productGB;
var destGB;

function JsTakeProductToOrder(product) {    // This is the function to be executed 
	if (window.opener) {                    // when user clicks "Add this product..."
		productGB = product;
		destGB = window.opener;
		JsDeliverProduct();	
	}
	if (!window.opener) {
		productGB = product;
		if  (typeof destGB == 'undefined') {
			destGB = window.open("addOrder.php");
		}
		else {
			JsDeliverProduct();
		}
	}
}

/*The function JsDeliverProducts here just basically assings values to
variables in destGB like "destGB.productID = document.getElementById(productGB)..."
and then at the end executes destGB.addRow() which is on the "add order"-page

If the above function is executed with it not being opened by the "add order"-page.
The page gets opened and when its loaded (<body onload="JsPageLoaded[]">) the JsPageLoaded
function executes JsTakeProductToOrder() function on its opener being this page right here.

I might suck at explaining this but still.
*/

//  The relevant code in the "add order"-page

function JsPageLoaded() { // If the page has been opened by the "search for products"-page it menas
	if (window.opener) {  // that there is a product information to be collected.
		window.opener.JsTakeProductToOrder();
	}
}

function JsAddProduct () { // This function fires when "Add products" button is clicked and opens
	if (!window.opener) {  // the "search for products"-page if its not already open.
		if  (typeof search == 'undefined') {
			search = window.open("searchProducts.php");
			search.focus();
		}
	}
}

function JsAddRow() {
	alert(code+" "+title+" "+units+" "+netPrice+" "+vat);
	search.focus();
}
&#13;
&#13;
&#13;

我希望你能理解我所追求的目标。我刚刚开始使用网络编程,但我对嵌入式系统和PLC有一些经验:s。

0 个答案:

没有答案
相关问题