在url中使用javascript更改框架属性 [英] Change Frame properties with javascript in the url

查看:62
本文介绍了在url中使用javascript更改框架属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我的意思是如果url是:



mywebpage.com/example.html?width=800&height=450



iframe是

< iframe width =800height =450scrolling =noframeborder =0allowtransparency = truemarginwidth =0marginheight =0src =http://mips.tv/embedplayer/test121/1/800/450>< / iframe>



请参阅iframe中的宽度和高度值两次 我有一个示例,但现在正在iframe的src值

http://redzeronline.ucoz.com/xd.html?width=800&height=450

解决方案

'/'字符保留用于查找文件夹。如果你使用查询,情况会更好。



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

  //其中frame是您在上面显示的iframe:
var query = JSON.parse(('{'+(frame.source.substr(1).replace(new RegExp (([^ =] +)=([^&] +)&?,'g'),function(){return'''+ arguments [1] +': 2] + ' ';}))+'}')代替(/,\} /。 }));

无论如何,我想你也可以使用你想要的格式的正则表达式。

  var width = -1; 强烈 
var height = -1;
...
// frame是您显示的iframe。
//你应该考虑添加一个id属性,以便以后可以识别它。
//这是很好的编码练习。
var results = frame.match(/([0-9] +)\ /([0-9] +)$ /);
if(results.length == 3)
{
width = parseInt(results [1]);
height = parseInt(results [2]);
}
else
{
//出错了...
}

如果您想更改框架大小,只需调用 replace()而不是 match()。确保您按照 EcmaScript标准所述传递函数。



要了解关于JavaScript中正则表达式的更多信息,请参阅这个网页


I want to change the size of an iframe with javascript according to the URL,

I mean that if the url is:

mywebpage.com/example.html?width=800&height=450

the iframe is

<iframe width="800" height="450" scrolling="no" frameborder="0" allowtransparency="true" marginwidth="0" marginheight="0" src="http://mips.tv/embedplayer/test121/1/800/450"></iframe>

See that the width and height values are twice each in the iframe

I have an example here but its now working in the src values of the iframe

http://redzeronline.ucoz.com/xd.html?width=800&height=450

解决方案

The '/' character is reserved for locating a folder. It would be better if you use a query.

A regular expression would be useful for a query.

//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(/,\}/,"}"));

Anyway, I guess you could also use regular expressions for the format that you want. I just strongly urge you to use a query string.

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...
}

If you want to change the frame size, just call replace() instead of match(). Make sure you pass a function as described at the EcmaScript standards.

To learn more about Regular Expressions in JavaScript, see this webpage

这篇关于在url中使用javascript更改框架属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆