i have a link that looks like this
is it possible to read variables from this url likeCode:href="#/work/companyName1"
is it possible to somehow add a ?id=someVariableCode:if(#/work="companyName1" ){$link = "http://www.companyName1.com";}
i have a link that looks like this
is it possible to read variables from this url likeCode:href="#/work/companyName1"
is it possible to somehow add a ?id=someVariableCode:if(#/work="companyName1" ){$link = "http://www.companyName1.com";}
I am confused to about your question. Do you mean something like this:
Then yes but the link has to have a file name after the domain name to reference to then you can add several ?id=someVariable separated by &PHP Code:if(#/work="companyName1" ){$link = "http://www.companyName1.com/file.php?id=someVariable";}
If that is not what you mean please give some more examples of what you think it should look like.
What's the relationship between the variable and the link or how is the link determined?
Corrections to my coding/thoughts welcome.
my href links do not have the ".php" suffix because the site does not have html container , rather it is a wide scrolling page using javascript so the href is simply
but i would like to pass some sort of variable from page to page and th only way i know how is to use theCode:href="#/work/page1"
Code:somelink.php?var=123otherVar=456
if its impossible to read href without a ".php" since i cannot add "?var=123"
can i read the entire url and work from there?
When an href starts with a hash (#), unless the server is parsing that into something else as the page is served, it's not a link to another page, rather a link to a named anchor on the same page.
So:
would scroll to:Code:href="#/work/page1"
if found, to the top of the page if not. If you add a query string:HTML Code:<a name="/work/page1">Optional Text</a>
It will go to the named anchor at the bottom, and the query string will appear in the address bar, but the server side code at the top will not echo anything.PHP Code:<?php
if(isset($_GET['bob'])){
echo $_GET['bob'];
}
?>
<a href="#/work/page1?bob=Fred's Friend">GoTo /work/page1?bob=Fred's Friend</a>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<a name="/work/page1?bob=Fred's Friend">/work/page1?bob=Fred's Friend</a>
If you want some other type of behavior, you either need javascript or some other type of syntax. Since to be valid the query string must always precede the hash in a URL, you can do:
Now the query will appear in the address bar, and the page will scroll to the named anchor (which is different here, it has no query in it), and the server side code will echo:PHP Code:<?php
if(isset($_GET['bob'])){
echo $_GET['bob'];
}
?>
<a href="?bob=Fred's Friend#/work/page1">GoTo /work/page1</a>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<a name="/work/page1">/work/page1</a>
at the top of the page.Fred's Friend
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
thank you for replying. i also need to mention that i found this piece of code and implemented on the site
the file switch.php is called when one of the anchor buttons are pressed and its in this file that i want to write a condition so that it loads dynamic markup such asCode:$.ajax({ beforeSend: function () {}, data: {id:id,gateway:'detail'}, success: on_query_success, error: function () {}, url: 'switch.php' });
but these variables do not registerCode:<?php if($id=="1" ){$link = "http://coke.com"; $title="Coke"} else if($id=="2" ){$link = "http://pepsi.com"; $title="Pepsi"} echo "<div id='divOne'><h1>$title</h1><h2 class='link'>\n"; echo "</div>\n"; echo "<div id='someClasss'>\n"; echo "<div class='someClass'><img src='images/client1/a.jpg' alt='' /></div>\n"; echo "<div class='someClass'><img src='images/client1/b.jpg' alt='' /></div>\n"; echo "<div class='someClass'><img src='images/client1/c.jpg' alt='' /></div>\n"; echo "<div class='someClass'><img src='images/client1/d.jpg' alt='' /></div>\n"; echo "</div>"; ?>
Code:<li> <a href="#/work/coke?id=1" rel="coke">coke</a> </li> <li> <a href="#/work/pepsi?id=2" rel="pepsi">pepsi</a> </li>
Last edited by ggalan; 09-23-2010 at 04:13 AM.
Like I said, to even have a chance of working, they would need to be like:
Otherwise they are not valid query strings, and will not register as anything other than as part of the hash string. The hash always comes after the query. If this were a full URL, to be a valid query, it would be something like:Code:<li> <a href="?id=1#/work/coke" rel="coke">coke</a> </li> <li> <a href="?id=2#/work/pepsi" rel="pepsi">pepsi</a> </li>
Not:Code:href="index.php?id=2#/work/pepsi"
as you are more or less currently doing it.Code:href="index.php#/work/pepsi?id=2"
This should be independent of any javascript and will work just fine, unless the javascript cancels or in some other way renders moot the default action of these links.
Also, your PHP code here:
will not pick up the query $_GET data anyway, unless your server is really lax about how it does this, or you have a more formal method for getting the $_GET data into the $id variable higher up on the page that you are not showing in your post.PHP Code:if($id="1" ){$link = "http://coke.com"; $title="Coke"}
else if($id="2" ){$link = "http://pepsi.com"; $title="Pepsi"}
Last edited by jscheuer1; 09-22-2010 at 04:48 PM. Reason: English usage
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
would i need this on top?Also, your PHP code here:
if($id="1" ){$link = "http://coke.com"; $title="Coke";}
else if($id="2" ){$link = "http://pepsi.com"; $title="Pepsi";}
will not pick up the query $_GET data anyway, unless your server is really lax about how it does this, or you have a more formal method for getting the $_GET data into these variables higher up on the page that you are not showing in your post.
Code:$id = $_GET['id'];
i tried placing the "?id=1" before the hash and now the whole thing doesnt work. any suggestions on how to make that "switch.php" page dynamic?
since the url is unique, can i write a condition based on the changing url? how would one do that??
Bookmarks