用window.open在打开网页中接收get方法地址中的参数变量值

寻技术 R语言 2023年07月08日 117

用html中的方法window.open打开弹出的界面中接收类似于get方法获取地址中的参数变量值。

html中用window.open提交数据:

<script>
	 function open_print(){
	 		prv=$('#num_result').val()
	 		window.open('print.html?v='+prv);
	 }
</script>

html页面中JS接收界面:

<script>
	function GetRequest() {
		var url = location.search; //获取url中"?"符后的字串
		var theRequest = new Object();
		if (url.indexOf("?") != -1) {
			var str = url.substr(1);
			strs = str.split("&");
			for(var i = 0; i < strs.length; i ++) {
				theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
			}
		}
		return theRequest;
	}
	
	var Request = new Object();
	Request = GetRequest();
	
	print_str= Request['v'];
</script>
关闭

用微信“扫一扫”