有没有人知道会检测页面的动态url(?q = Chicken)的JavaScript代码,并将页面上的iframe的url设置为https://www.google.co.uk/?#q=Chicken。 (我实际上没有制作谷歌搜索客户端!)设置基于动态URL的iframe url
Get - Text added to Url
set
Url of iframe to https://www.google.co.uk/?#q=Chicken
这将全部上传。
有没有人知道会检测页面的动态url(?q = Chicken)的JavaScript代码,并将页面上的iframe的url设置为https://www.google.co.uk/?#q=Chicken。 (我实际上没有制作谷歌搜索客户端!)设置基于动态URL的iframe url
Get - Text added to Url
set
Url of iframe to https://www.google.co.uk/?#q=Chicken
这将全部上传。
你需要的东西是这样的:
<script>
function get_url_parameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
document.addEventListener('DOMContentLoaded', doc_loaded, false);
function doc_loaded() {
//var url = 'https://www.google.co.uk/?#q=' + get_url_parameter('q');
var url = 'http://example.com/?#q=' + get_url_parameter('q');
document.getElementById('iframe_id').src = url;
}
</script>
<iframe src="#" id="iframe_id" width="1000" height="500"></iframe>
,而是因为它发送一个“X-框选项:SAMEORIGIN”它不会为谷歌工作的响应头:(
试试这个,网址浏览“http://something.com/index.asp?search=anything
<script type="text/javascript">
$(document).ready(function()
{
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var urliframe = "http://www.google.co.uk/?#q="+getParameterByName('search');
$('#myIframe').attr('href',urliframe);
});
</script>
<iframe id='myIframe' href='#'>
可以在JavaScript中使用location.search
https://developer.mozilla.org/en-US/docs/Web/API/URLUtils.search
因此,一个例子是:
$('iframe')[0].src = "http://www.google.co.uk/" + location.search;
但是,谷歌不喜欢要在iframe中,您应该尝试其他网站。
什么服务器端语言使用的是? –
您可以获取动态url,从'?'做一个子字符串并获取参数。 –