Wednesday 15 January 2014

jquery - Change Frame propierties with javascript in the url -


I want to resize an iframe with javascript according to URL,

I mean If url is:

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

iframe

< Code> & lt; Iframe width = "800" height = "450" ​​scrolling = "no" frameborder = "0" permission representative = "true" margin width = "0" margin-height = "0" src = "http: // mips .tv / embedplayer / Test121 / 1/800/450 "& gt; & Lt; / Iframe & gt;

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

Here I have an example, but now it is working in the source values ​​of iframe

"post-text" itemprop = "text"> If you use a query then this is better Will happen.

A regular expression will be useful for queries.

  // Where the frame is the above iframe shown to you: var query = JSON.parse (('{' + (frame.source.substr (1) .replace (new RegExp ("( [^ =] +) = ([^ & Amp;; +] & amp; ??, 'g'), work () {return '' '+ argument [1] +' ":" '+ logic [2] ] + '",';})) + '}'). Substitution (/, \} /,"} "));   

Anyway, I can also use regular expressions for the desired format. I simply urge strongly to use a query string.

  var width = - 1; Var height = -1; ... // frame that Iframe is what you show // You should consider adding that ID attribute so that you can recognize it later // This is a good coding practice Var result = frame. Match (/ ([0-9] +) \ / ([0-9] +) $ /); if (results.length == 3) {width = parseInt (result [1]); height = parseInt (result [2]);} Else {// something is wrong Gone ...}   

If you want to change the frame size, then just replace () instead of mail () . Make sure that you are described according to the function.

To learn more about regular expressions in JavaScript, see

No comments:

Post a Comment