Super Web Mart - Discount Coupons & Deals - Discount Promos, Coupon Codes, Discount deals and web site reviews
 

Author Topic: Scripting <a href=>  (Read 2766 times)

0 Members and 1 Guest are viewing this topic.

Offline David

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Scripting <a href=>
« on: August 23, 2007, 02:27:16 AM »
I need to append a string to url's being referenced in an HREF. This is on a CF page and I want to pass along the same query string that was passed in to this page. The reason I want to use a JavaScript function is that the query string may be several hundred characters and there may be several hundred links on the page, and I want to limit the size of the page generated.

Without using JavaScript this looks like:

...
<cfloop query="q">
<a href="mypage.cfm?item=#q.itemnum#&#cgi.query_string#">#q.name#[/url]
</cfloop>
...

I figure that I'd expand cgi.query_string using CF within a JavaScript function so that this text is included only once in the html generated for the page. Any ideas how this can be done?

Thanks,
David

Webmaster Forum

Scripting <a href=>
« on: August 23, 2007, 02:27:16 AM »

Offline Reema Khan

  • Full Member
  • ***
  • Posts: 184
    • View Profile
Re: Scripting <a href=>
« Reply #1 on: August 23, 2007, 02:42:36 AM »
David,

Here you go....

<script language="JavaScript">
function GotoURL(url) {
window.location = url+'&<cfoutput>#cgi.query_string#</cfoutput>';
}
</script>

<cfloop query="q">
<a href="javascript:GotoURL('mypage.cfm?item=#q.itemnum#');">#q.name#[/url]
</cfloop>

Offline David

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Scripting <a href=>
« Reply #2 on: August 23, 2007, 02:48:25 AM »
Thanks Reema. That works a charm.

In a related vein: Is there a way to have a javascript function return a string that could be used directly within the href? I tried it a couple ways but kept getting errors. This might just be a lack of understanding on my part of how the event model operates.

Offline Reema Khan

  • Full Member
  • ***
  • Posts: 184
    • View Profile
Re: Scripting <a href=>
« Reply #3 on: August 23, 2007, 02:52:53 AM »
David,
Not sure what you mean. I'll cover a couple interpretations below...

1) You could use JavaScript to write the entire anchor tag, but to get it to write just href attrib inside the anchor, stumps me. And just thinking about it makes me think there is a better way to do what your trying to do.

2) You can use JavaScript to read/write the anchor's href attribute through DOM. I believe it's document.linkname.href where linkname used <ahref="whatever.htm" name="linkname">.


Do that help?

Offline David

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Scripting <a href=>
« Reply #4 on: August 23, 2007, 02:54:38 AM »
I was just wondering if something similar to the link below would be possible. I imagine the original solution is the closest. No big deal.
Thanks.

<a href="javascript:GetMyURL()">some link[/url]

David

Offline rachel

  • Jr. Member
  • **
  • Posts: 23
    • View Profile
Re: Scripting <a href=>
« Reply #5 on: December 10, 2009, 11:58:38 PM »
hey devid just give me time for use this . after use this function i can tell you clearly. otherwise it will be fake.

Offline aashleyy12

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Re: Scripting <a href=>
« Reply #6 on: July 05, 2010, 07:57:00 PM »
Is there a way to have a javascript function return a string that could be used directly within the href? I tried it a couple ways but kept getting errors. This might just be a lack of understanding on my part of how the event model operates.
__________________________________________
Hotel Italy
Apartments Italy

Webmaster Forum

Re: Scripting <a href=>
« Reply #6 on: July 05, 2010, 07:57:00 PM »