Forum Moderators: open
I am trying to get an external file to load and display when a condition is met.
What happens is, the page is a list of events that is dynamically generated server-side. There is a jump-link pointing to each event from the previous page(eg. /events_10-2003.html#12345). I need the external script to load directly under the event listing that the link jumps to.
Now, I have already found out that there is no way to get the value of the anchor (#12345) server-side, so I went to js.
Here is what I tried:
Head:
str = window.location.hash;
str = str.substr(1);Body(this script appears after every listing):
if (str == <?=$db->f("id")?>) {
document.write("<script type=\"text/javascript\" src="ht*p://www.site.com/script.js\"></script>");
It works as planned in my Opera browser but IE shows the js in the wrong place.
If anyone can shed some light, I would appreciate it.
Birdman
Sorry, it's a typo. It's correct in the actual file. It just looks like IE doesn't want to display it in the right place.
If I just call the file from the html like this:
<script type="text/javascript" src="..."></script>
It appears in the right position but I have no way of knowing when to call it server side bacause I can't get the hash(anchor) value until it hits the client.
there is no way to get the value of the anchor (#12345) server-side
Do you mean this in a general sense? PHP f.i. has a function parse_url() which returns an array with a part called 'fragment', containing stuff after the hashmark #. Even without such a function, it can't be that hard to parse the documents location?
if (str == <?=$db->f("id")?> )
Maybe you need to quote the string:
if (str == '<?=$db->f("id")?>')
document.write("<script [...]></script>");
For valid HTML, you should escape the / in </script>. Otherwise some over-correct SGML parser might consider </ as the closing tag of your script.
Hope this helps...