Closed Thread Icon

Topic awaiting preservation: Passing Variable for Link (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8840" title="Pages that link to Topic awaiting preservation: Passing Variable for Link (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Passing Variable for Link <span class="small">(Page 1 of 1)</span>\

 
Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 08-31-2003 20:28

Here's the background: I'm creating a CD-ROM version of an existing site. Some of the site's features (e.g. business location finder) won't work on the CD, of course, so when a user clicks a link to those features, he instead gets a page that says "You must go the live site to access this feature ... blah blah blah ..." To continue, he clicks a button that takes him to the relevant page on the live site.

I'm using one document for that message and button, and am passing the path for the live document in the original link, like so:

<A HREF="go_live.html?dir/page.html">Feature X</A>

I've written some JavaScript for go_live.html to parse the URL and create the "continue" link, which seems to work, but I want to make sure I've done it correctly:

code:
<SCRIPT LANGUAGE="javascript">

var url = window.location.href

function delineate(str) {
page = str.indexOf("?") + 1;
return(str.substring(page));
}

var where = ("http://www.livesite.com/" + delineate(url));

</SCRIPT>



<A HREF="javascript:document.location.href=where;">Continue to the Live Site</A>






[This message has been edited by Wes (edited 08-31-2003).]

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-31-2003 21:01

This would be the most efficient way to do it...

where = "http://www.livesite.com/" + document.location.search.substr(1);




[This message has been edited by mr.maX (edited 08-31-2003).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-31-2003 21:52

mr.max: document.location isn't an object - it's simply a string value (which I believe is read-only) of the document's location. I believe you meant to use window.location (or just location), which is an object that has properties such as search and href.

Of course, both of them will work, but I believe that's just because browsers are being nice about it. However, I'm pretty sure that the proper one to use for this is window.location.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-31-2003 22:17

According to MSDN, "location" is an object which applies to document.* and window.* in MSIE JScript implementation...

However, I did a search on Google, and it turns out that document.location was an alias for read-only document.URL property a way back when Netscape 3.0 was released. So, I really don't know whether other browsers (i.e. Mozilla) "officially" treat document.location as object nowadays or not...


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 09-01-2003 00:07

Well, you can't trust MSDN, since that documents the ways that IE is nice to you =)

I'm sure most modern browsers *do* treat document.location as an object, but it's best to go with the original method, IMO.

Wes
Paranoid (IV) Mad Scientist

From: Inside THE BOX
Insane since: May 2000

posted posted 09-02-2003 02:12

That's what I get for stripping down a more complicated script. (And for not knowing what the hell I'm doing.)

Thanks!

BTW, I am linking the following bit correctly, aren't I? Or am I just lucky that it works? (I haven't tested in all browsers yet.)

<A HREF="javascript:document.location.href=where;">Continue to the Live Site</A>




[This message has been edited by Wes (edited 09-02-2003).]

« BackwardsOnwards »

Show Forum Drop Down Menu