我有以下代码:
<div class='trick' id='1234'>
<script src="/feeds/posts/default?max-results=50&orderby=published&alt=json-in-script&callback=maps_location"></script>
</div>
并且我正尝试将其替换为:
<div class='trick' id='1234'>
<script src="/feeds/posts/default/-/variableB?max-results=50&orderby=published&alt=json-in-script&callback=maps_location"></script>
</div>
我希望变量B等于last_segment变量
<script type='text/javascript'>
var segment_str = window.location.pathname;
var segment_array = segment_str.split( '/' );
var last_segment = segment_array.pop();
</script>
因此,我要尝试的操作是在当前网址中,例如http://XXXXXXX.blogspot.com/search/label/test
仅具有标签“ test”的回调供稿
有可能吗?
答案 0 :(得分:0)
我找到了解决方案。。。它工作得很好...
<div class='trick' id='1234'>
<script>
var segment_str = window.location.pathname; // return segment1/segment2/segment3/segment4
var segment_array = segment_str.split( '/' );
var last_segment = segment_array.pop();
document.write("<div id=\"12345\"><script src=\"https:\/\/tinosemagazine-new.blogspot.com/feeds/posts/default/-/"+last_segment+"?max-results=100&orderby=published&alt=json-in-script&callback=maps_location\"><\/script><\/div>");
</script>
</div>