2017-10-11 122 views
-1

我想从这个网址获取并IFRAME打印哈希

http://www.mywebsite.com/#/aaaaaaaa 

AAAAAAAA

获得哈希并添加iframe中:

<iframe src="http://www.example.com/url/aaaaaaaa" frameborder="0"> 

Javascript代码:

<script> 
var hhash = window.location.hash.substr(1); 
alert(hhash); 
</script> 
+0

还有呢?你已有的代码有什么问题?即你的问题是什么?另外,您想要将散列添加到iframe,或者更确切地说,添加到iframe的src中? – Teemu

+0

是的,@Teemu我想要在iframe中自动打印“aaaaaaaa”与javascript – ericdrey

+0

https://stackoverflow.com/questions/24603580/how-can-i-access-the-dom-elements-within-an-iframe虽然,它看起来像你滥用'location.hash',也许你应该使用查询字符串呢? – Teemu

回答

0

您也可以使用lastIndexOf()函数来定位你的URL /字符最后一次出现,那么SUBSTR()函数返回从该位置开始的字符串:

var hhash =(window.location.href.substr(window.location.href.lastIndexOf('/') + 1)); 
document.write("<iframe src=\"example.com/url/\""+hhash+"frameborder=\"0\">"); 
+0

谢谢@Osama,但我想打印var hhash ..“aaaaaaaa”in iframe like this