是否有人知道将检测页面动态网址的javascript代码(?q = Chicken)并将页面上iframe的网址设置为https://www.google.co.uk/?#q=Chicken。 (我实际上并没有制作谷歌搜索客户端!)
Get - Text added to Url
set
Url of iframe to https://www.google.co.uk/?#q=Chicken
这将全部上传。
答案 0 :(得分:1)
试试这个,浏览网址“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='#'>
答案 1 :(得分:1)
您可以在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。你应该尝试另一个网站。
答案 2 :(得分:1)
你需要这样的东西:
<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>
但它对Google不起作用,因为它发送了一个&#34; X-Frame-Options:SAMEORIGIN&#34;响应标题:(