开发者

dynamic link based on your current url

I know this will sound odd but stay with me on this.

I am trying to create a link that will dynamically add on ending string of the current url.

Example:

you are looking at an open window with a url of www.yahoo.c开发者_JAVA百科om/(*lucky.aspx*)

and the link on the page reads

<a href="www.lucky.com/(replace with just *lucky.aspx* url)[Google analytic code]">LOOK A LINK</a>

The problems I am faced with is that I need to shave down everything before the "/" and preserve everything after the .aspx

The code I have so far goes like this

<script type="text/javascript">
            window.onload = function() { 
                var grabedurl = window.location.href
                document.getElementById('url').value=grabedurl; 
            }
</script>
<a href="www.lucky.com/(some element id=url)[Google analytic code]">LOOK A LINK</a>

Thanks for any help you can offer.


Updated code

<script type="text/javascript">
  window.onload = function() { 
    var grabedurl = window.location.pathname + window.location.search;
    document.getElementById('url').src = "http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.example.com"+grabedurl+"&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;font=arial"; 
  }
</script>
<iframe id="url" src="" style="overflow: hidden; border: 0px none; width: 90px; height: 25px;"></iframe>


I'm not completely sure what you are asking, but would this be something you'd need?

<script type="text/javascript">
  window.onload = function() { 
    var grabedurl = window.location.pathname + window.location.search;
    document.getElementById('url').href = "http://www.lucky.com" + grabedurl + "[Google analytic code]"; 
  }
</script>
<a href="www.lucky.com[Google analytic code]" id="url">LOOK A LINK</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜