简体   繁体   English

使用get in javascript将数据发送到iframe

[英]Send data to iframe using get in javascript

i create one button in html 我在html中创建一个按钮

<input type="button"  value="Simulate" class="submit_btn"  id="stimulate" />

and use jquery onclick event and create iframe , i want to send lat, long and title to iframe and create dynamic map but i send get 10 % discount as a subtitle , i get following error 并使用jquery onclick事件并创建iframe,我想将lat,long和title发送到iframe并创建动态地图,但是我发送10%的折扣作为副标题,出现以下错误

GET http://domain name/name of controller/name of function/57.643821505750964/12.180534033203116//get%2010%%20discount 400 (Bad Request)



$("#stimulate").click(function() {
var ad_lng = document.getElementById("longclicked").value;
var ad_subtitle = document.getElementById("ad_subtitle").value;
var ad_lat = document.getElementById("latclicked").value;

$('#iframeHolder').html('<iframe id="iframe" src="<?php echo base_url(); ?>index.php/admin/frame_stimulator/'+ad_lat+'/'+ad_lng+'/'+ad_subtitle+'" width="700" height="550" scrolling="no"  frameborder="0"></iframe>');
}

how can i send data to iframe . 如何将数据发送到iframe。 i dont want to use form and send data by post method.. without using form i can post data to iframe 我不想使用表格并通过发布方法发送数据..不使用表格我可以将数据发布到iframe

Pass them in the query string: 在查询字符串中传递它们:

var ad_lng = encodeURIComponent( document.getElementById("longclicked").value );
var ad_subtitle = encodeURIComponent( document.getElementById("ad_subtitle").value );
var ad_lat = encodeURIComponent( document.getElementById("latclicked").value );

$('#iframeHolder').html('<iframe id="iframe" src="<?php echo base_url(); ?>index.php/admin/frame_stimulator?ad_lat='+ad_lat+'&ad_lng='+ad_lng+'&ad_subtitle='+ad_subtitle+'" width="700" height="550" scrolling="no"  frameborder="0"></iframe>');

In codeigniter code you would retrieve them: 在codeigniter代码中,您将检索它们:

$lat = $this->input->get("ad_lat");
$lng = $this->input->get("ad_lng");
$subtitle = $this->input->get("ad_subtitle");

You can invoke a javascript function in an iframe from the parent/container page. 您可以从父/容器页面的iframe中调用javascript函数。 So if you script a function in the iframe page that takes data as a parameter, then you can invoke it from the main page that contains iframe. 因此,如果您在iframe页面中编写一个以数据为参数的函数的脚本,则可以从包含iframe的主页中调用它。

Check this: Invoking JavaScript code in an iframe from the parent page 检查一下: 从父页面在iframe中调用JavaScript代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM