javascript - Iframe src attribute change with parameter -
i’m trying change src
attribute of <iframe>
depending if iframe src
has /?foo or not.
i had solution:
<script> jquery(document).ready(function($) { $('iframe[src*="?foo"]').each(function() { $('#frame').attr('src', "http://www.example.com/page2"); }); }); </script> <iframe id="frame" src=„www.example.com/page1/?foo"></iframe>
but problem have no access page, iframe emded can't write code <head>
of site.
i have access both pages www.example.com/page1
, www.example.com/page2
i don’t know how need change code manipulate src
.. not sure if possible, when have no access page iframe
as seen in how retrieve parameters javascript? can use following code , call function parsesecond("foo")
foo
parameter on page1. can find more information on question page.
function parsesecond(val) { var result = "not found", tmp = []; var items = location.search.substr(1).split("&"); (var index = 0; index < items.length; index++) { tmp = items[index].split("="); if (tmp[0] === val) result = decodeuricomponent(tmp[1]); } return result; }
if want redirect page 2 can write following code redirect frame page1 page2 when foo parameter has value equal bar.
if(parsesecond("foo")=="bar"){ window.location="www.example.com/page2"; }
Comments
Post a Comment