如何在JS文件中获取JS后面参数?

JavaScript010

如何在JS文件中获取JS后面参数?,第1张

这个获取参数的方法有多种,比如:url 传值(a.html?id=1),

窗体传值:

a.html:

function doopen(){

//打开一个子窗体

var aa = window.showModalDialog("b.html","可以传到子窗口的一个值","dialogHeight=200pxdialogWidth=300px")

//接收子窗体传过来的值

document.getElementById('temp').value = aa

}

b.html:

//获取父窗体传过来的值

var aa = window.dialogArguments

alert(aa)

function doClose(obj){

//返回值给父窗体

window.returnValue = obj.innerHTML

//关闭本窗体

window.close()

或者,把值写到文档中。。。不考虑其他的,传值的方法有很多种

这个参数在js里面是无法获取的,

想要在js中使用,可行方案是服务端处理www.xxx.com/xxx.js这个请求的,获取到url中的参数,然后通过response写到js文件内容中去

还有个受限制的方式就是用script标签加载www.xxx.com/xxx.js?a=xx&b=xx,js中获取该script标签dom,读取src属性,解析字符串即可

function Test(){

var url=window.location.href

var first=url.indexOf("_")+1

var second=url.lastIndexOf("_")+1

alert("the first param value:"+url.substr(first,second-first-1))

var point=url.lastIndexOf(".")

alert("the second param value:"+url.substr(second,point-second))

}