使用jquery或javascript将url参数传递给iframe [英] passing url parameters to iframe, using jquery or javascript
问题描述
经过互联网搜索后,我终于决定发布这个问题。
After searching a lot over the internet I finally decided to post this question.
我正在使用THICKBOX jquery选项卡。当点击任何标签时,我想要将URL.IDNUMBER传递给标签页上的iframe。
我能够发送IDNUMBER并在主页上使用jquery在文本框中显示
I am using THICKBOX jquery tabs.When any of the tab is clicked I want to pass the URL.IDNUMBER to the iframe which on tab pages . I was able to send the IDNUMBER and display it in a text box by simply using jquery on the main page
$("#mytest").val('IDNUMBER');
标签页:
<input id="mytest" name="IDNUMBER" type="text">
但是我无法将idnumber作为url参数传递给iframe。标签页是一个HTML页面。
But am unable to pass the idnumber as a url parameter to the iframe.The tab page is an HTML page.
谢谢
推荐答案
今天我遇到了同样的问题。我用以下方法解决了这个问题:
Today I faced the same problem. I solved it with the following approach:
<iframe id="inviteFriendsFrame" src ="location_to_iframe?paremater1=value1¶meter2=value2" width="529px" height="300"></iframe>
然后在iframe中我们可以从javascript解析GET,我用过这个
Then inside the iframe we can parse the GET from javascript, I've used this
http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
function getUrlVars() { // Read a page's GET URL variables and return them as an associative array.
var vars = [],
hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
所以我得到了所有的变量,因此可以这样做:
so then I had all the get variables and therefore could do so something like:
parameters = getUrlVars(); //which leads to:
console.log(parameters['param1']); //Writes 'value1' to console
希望我帮助过。请注意,虽然链接来自jQuery网站,但代码是通用JavaScript。
Hope I've helped. Please note that although the link is from a jQuery site, the code is generic JavaScript.
这篇关于使用jquery或javascript将url参数传递给iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!