【发布时间】:2018-04-06 21:55:53
【问题描述】:
我有一个网页,其中包含使用 iframe 的嵌入页面。我已经解析了 URL 以将参数附加到主 url 以创建新链接,但现在我需要将路径传递给 iframe src 以在单击链接时加载页面。
iframe 代码
<iframe name= "myiframe" id = "load" src="https://www.site-name.com/Manual/application.htm">
解析url的jQuery代码
$(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
新网址现在是https://www.site-name.com/f1?page=module_1_5_3.htm
这可行,但现在我需要将查询路径传递给 iframe src 以在单击链接时加载页面。
我想要做的是将路径传递给 iframe src。 如何将路径变量传递给 iframe src。
【问题讨论】:
标签: javascript jquery html iframe