根据动态Url设置iframe网址 [英] Set iframe url based on dynamic Url
本文介绍了根据动态Url设置iframe网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道会检测页面动态网址的JavaScript代码(?q = Chicken),并将页面上的iframe网址设置为 https://www.google.co.uk/?#q=Chicken 。 (我实际上并没有做一个谷歌搜索客户端!)
Does anybody know a javascript code that will detect the dynamic url of the page (?q=Chicken) and set the url of the iframe on the page to https://www.google.co.uk/?#q=Chicken. (I am not actually making a google search client!)
Get - Text added to Url
set
Url of iframe to https://www.google.co.uk/?#q=Chicken
这将全部上架。
This will all be onload.
推荐答案
您需要如下所示的内容:
You need something like this:
<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,因为它发送了X-Frame-Options:SAMEORIGIN响应标题:(
but it will not work for Google because it's sending an "X-Frame-Options: SAMEORIGIN" response header :(
这篇关于根据动态Url设置iframe网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文