0

I have to use one of my html page as an iframe in some other site (not in same domain. need to use it like a widget.) In my iframe url there are some parameters

ex: < iframe src="www.MyTestSite.com/Home.html?id=3" width="800" height="300">< /iframe>

The html page I'm using as the iframe (www.MyTestSite.com/Home.html?id=3) has a button and in that button click function i need to read that "id" parameters value. But if i use window.location.href for read it I'm unable to read that value since the iframe loaded in some other page (other domain ex: www.example.com/index.html)

Is there any way to get that iframe url query string value inside onlick function? My page only display as an iframe not as a whole page and in some different domain too.

(What i want is, to read that iframe url "id" parameter inside a button click function. iframe loads in some other domain page. So when ever i use window.location.href i dont get my iframe url. The button i mentioned about contained in y iframe page. when ever i click that button i need to read that "id" parameter)

Thanks in advance

user2837480
  • 349
  • 2
  • 18
  • you can open a different url page using `window.open()` just in case might be useful. – MrNew Mar 04 '17 at 19:35
  • @MrNew - you mean before i read the parameter value should reopen the page in another tab..? – user2837480 Mar 04 '17 at 19:43
  • Hm I can't answer with a code because its been marked as duplicate, but you can create your button `` then create that function and pass that `iframeId` argument in the function then do `var getSrc = document.getElementById('your-iframe-id"); alert(getSrc.src)` this should give you the iframe Url but its probably not the best as it targets specific `id` https://plnkr.co/edit/GI5rho44Ik3DfJlYKk5x?p=preview – MrNew Mar 04 '17 at 20:13
  • @MrNew Thank you for the reply. Actually this is not a duplicate question. i checked their solutions as well. They are about set url parameters from server side. that's not what i want here. – user2837480 Mar 05 '17 at 09:39
  • create a new question if its not a duplicate otherwise people can't show code as their answer then comment back here so people can see your new question. – MrNew Mar 05 '17 at 14:45

0 Answers0