Передача переменной в скрипт src - PullRequest
0 голосов
/ 30 июня 2019

У меня есть следующий код:

<div class='trick' id='1234'>
  &lt;script src=&quot;/feeds/posts/default?max-results=50&amp;orderby=published&amp;alt=json-in-script&amp;callback=maps_location&quot;&gt;&lt;/script&gt;
</div>

, и я пытаюсь заменить это на:

<div class='trick' id='1234'>
      &lt;script src=&quot;/feeds/posts/default/-/variableB?max-results=50&amp;orderby=published&amp;alt=json-in-script&amp;callback=maps_location&quot;&gt;&lt;/script&gt;
    </div>

, где я хочу, чтобы переменная B равнялась переменной last_segment

<script type='text/javascript'>
var segment_str = window.location.pathname;
var segment_array = segment_str.split( &#39;/&#39; );
var last_segment = segment_array.pop();
</script>

Итак, я пытаюсь сделать это по текущему URL-адресу, например http://XXXXXXX.blogspot.com/search/label/test

, чтобы иметь фид обратного вызова только для метки "test"

Возможно ли это?

1 Ответ

0 голосов
/ 30 июня 2019

Я нашел решение .... Оно отлично работает ...

<div class='trick' id='1234'>
<script>
var segment_str = window.location.pathname; // return segment1/segment2/segment3/segment4
var segment_array = segment_str.split( &#39;/&#39; );
var last_segment = segment_array.pop();

                              document.write(&quot;&lt;div id=\&quot;12345\&quot;&gt;&lt;script src=\&quot;https:\/\/tinosemagazine-new.blogspot.com/feeds/posts/default/-/&quot;+last_segment+&quot;?max-results=100&amp;orderby=published&amp;alt=json-in-script&amp;callback=maps_location\&quot;&gt;&lt;\/script&gt;&lt;\/div&gt;&quot;);
                            </script>
</div>
...