SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Wisconsin
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php echo tag within JS not working in Mozilla/NS

    Hello, I have a javascript which has a component that, based on the contents of "var location", it will change something in the script. As I want this to change based on which page the user is visiting, I placed this tag at the top of my pages;
    Code:
    <? $location = ""; ?>
    , and this is in the script:
    Code:
    var location = '<? echo ($location) ?>';
    I call the same script from multiple pages, and just change the contents of $location in each different page. This works perfectly in IE, but Mozilla and Netscape just freeze up and cannot even display the page, all because of var location = '<? echo ($location) ?>'; in the javascript script.

    Does anyone have suggestions for how to fix this? Or a workaround?

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2003
    Location
    Tulsa, OK
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why it would work in IE but not netscape, but shouldn't the code be:
    Code:
    var location = '<? echo ($location); ?>';

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using some other variable name. location is the same as window.location - not a reserved word specifically, but a key global browser property best left alone.
    ::: certified wild guess :::

  4. #4
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Wisconsin
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adios
    Try using some other variable name. location is the same as window.location - not a reserved word specifically, but a key global browser property best left alone.
    Thank you, I changed it from "location" to "loc", and it works perfectly in all browsers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •