Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将参数传递给iframe src_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript 将参数传递给iframe src

Javascript 将参数传递给iframe src,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我有一个网页,其中包含使用iframe的嵌入式页面。我已经解析了URL,将参数附加到主URL以创建新链接,但是现在我需要将路径传递到iframe src,以便在单击链接时加载页面 iframe码 解析url的jQuery代码 $(文档).ready(函数(){ var URL='1〕https://www.site-name.com/f1“;//主要 var otherURL=https://www.site-name.com/Manual/module_1_4_2.htm“;//ifra

我有一个网页,其中包含使用iframe的嵌入式页面。我已经解析了URL,将参数附加到主URL以创建新链接,但是现在我需要将路径传递到iframe src,以便在单击链接时加载页面

iframe码

解析url的jQuery代码
$(文档).ready(函数(){
var URL='1〕https://www.site-name.com/f1“;//主要
var otherURL=https://www.site-name.com/Manual/module_1_4_2.htm“;//iframe URL
//创建一个新链接,url作为其href:
变量a=$(''{
href:otherURL
});
var sResult='Protocol:'+a.prop('Protocol')+'
'+'主机名:'+a.prop('hostname')+'
'+'路径:'+a.prop('pathname')+'
' var path=a.prop('pathname');//将路径传递到主URL var newURL=URL+“?page=“+path.substring(path.lastIndexOf(“/”)+1); //显示新URL $('span').html(sResult+“
新URL:”+newURL); //正确显示 //新网址:https://www.site-name.com/f1? 页面=模块_1_4_2.htm
新的url现在是
https://www.site-name.com/f1?page=module_1_5_3.htm

这是可行的,但现在我需要将查询路径传递给iframe src,以便在单击链接时加载页面

我试图做的是将路径传递给iframe src。 如何将path变量传递给iframe src。

使用jQuerys函数更改iframe的
src
属性

var url=$(“#加载”).attr('src');
变量a=$(“#link”);
var path=a.prop('pathname');
var redirectUrl=url+“?page=“+path.substring(path.lastIndexOf('/'))+1);
$(“#加载”).load(重定向URL);



谢谢,我已经尝试过了,但似乎不起作用。目标是让测试Url在iframe中重新加载新页面。@pfiguer1我更新了我的答案。希望现在事情变得更清楚一点。我知道这是如何工作的,但我需要的是将查询路径传递给src,而您上面提供的没有做到这一点。@pfiguer1 by setting a
target
属性您正在将
href
中的任何内容作为
src
传递到您的iframe,而
href
是由jquery动态设置的。很抱歉,我没有得到您想要的结果。为了澄清,我正在尝试将此
页面=module_1_5_3.htm
传递到iframe src。谢谢
<iframe name= "myiframe" id = "load" src="https://www.site-name.com/Manual/application.htm">
  $(document).ready(function () {
var URL = 'https://www.site-name.com/f1'; // MAIN 

var otherURL = 'https://www.site-name.com/Manual/module_1_4_2.htm'; // iframe URL

//Create a new link with the url as its href:
var a = $('<a>', {
    href: otherURL
});
var sResult = '<b>Protocol:</b> ' + a.prop('protocol') + '<br/>'  + '<b>Host name: </b>' + a.prop('hostname') + '<br/>' + '<b>Path: </b>' + a.prop('pathname') + '<br/>' 

var path = a.prop('pathname');   // pass the path to the MAIN URL 
var newURL = URL + "?page="+ path.substring(path.lastIndexOf('/') + 1);

// display new URL 
$('span').html(sResult + "<br><b>New URL: </b>" + newURL);  

// Correctly displays
// New URL:https://www.site-name.com/f1? page=module_1_4_2.htm