Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在url中使用javascript更改框架属性_Javascript_Jquery_Html - Fatal编程技术网

在url中使用javascript更改框架属性

在url中使用javascript更改框架属性,javascript,jquery,html,Javascript,Jquery,Html,我想根据URL使用javascript更改iframe的大小 我的意思是,如果url是: mywebpage.com/example.html?宽度=800,高度=450 iframe是 请参见iframe中的宽度和高度值各为两倍 我这里有一个例子,但它现在在iframe的src值中工作 保留“/”字符用于查找文件夹。最好使用查询 正则表达式对于查询很有用 //where frame is the iframe you showed above: var query = JSON.parse(

我想根据URL使用javascript更改iframe的大小

我的意思是,如果url是:

mywebpage.com/example.html?宽度=800,高度=450

iframe是

请参见iframe中的宽度和高度值各为两倍

我这里有一个例子,但它现在在iframe的src值中工作


保留“/”字符用于查找文件夹。最好使用查询

正则表达式对于查询很有用

//where frame is the iframe you showed above:
var query = JSON.parse(('{'+(frame.source.substr(1).replace(new RegExp("([^=]+)=([^&]+)&?",'g'),function(){return '"'+arguments[1]+'":"'+arguments[2]+'",';}))+'}').replace(/,\}/,"}"));
无论如何,我想你也可以用正则表达式来表示你想要的格式。我强烈建议您使用查询字符串

var width = -1;
var height = -1;
...
//frame is the iframe that you show.
//You should consider adding an id attribute to that so that you can identify it later.
//It's good coding practice.
var results = frame.match(/([0-9]+)\/([0-9]+)$/);
if(results.length == 3)
{
   width=parseInt(results[1]);
   height=parseInt(results[2]);
}
else
{
   //something went wrong...
}
如果要更改帧大小,只需调用
replace()
而不是
match()
。确保传递的函数与中所述的相同


要了解有关JavaScript中正则表达式的更多信息,请参见

您的链接已断开/404