Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    tav
    tav is offline
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing php to external javascript

    Total programming newbie here but I'm doing some experimenting and can't solve this. Not even sure if it's possible, but here goes.

    I have a standard html page that calls an external javascript popup window. I want to be able to pass a php variable into the javascript and call it from within the .js file.

    ie, <script src=http://www.mydomain.com/script.js?1234></script>

    this calls the script.js to bring up the alert window. Now within the alert window, there is an action statement which directs the user to a URL. Now all I want to do is append the "1234" to the end of the url that is defined in the .js script.

    ie. script.js will contain the following line to point the visitor to somewhere.
    //action = "href='URL'"; // open URL case
    action = "HREF='http://www.outside.com/1234'";

    Basically I need to be able to parse the ?1234 somehow into the .js and be able to append the variable at the end or embed it within the URL I want the visitor to go to.

    hope that makes sense!

    Thanx for your help!

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Hi there,

    You could put some PHP into your parent page thus:

    PHP Code:
    <?php $page "1234"?>
    <A href="#" onclick="javascript:window.open('http://www.outside.com/<?php print($page); ?>');">Open the pop-up</A>
    Or

    PHP Code:
    <?php $page "1234"?>
    <A href="http://www.outside.com/<?php print($page); ?>" target="_blank">Open the pop-up</A>
    Here's an explanation that I found at random with a Google search: http://www.javascript-coder.com/wind...dow-open.phtml

    That being said, pop-ups are routinely blocked by web browsers, plus javascript can be turned off in a web browser's settings, and so I tend to write pages so that pop-ups are not necessary (ask yourself the question "how can I do this without javascript and pop-ups?") because end users (and that means anybody who can access the internet - which means anybody!) tend to be confused by pop-ups (my Mother, for example!), also people increasingly associate pop-ups with viruses and adware (in other words they make the mental association "pop-ups = dodgy website"). I for one also prefer to use web pages where everything is clearly presented in a single page without the need for javascript, pop-ups and the like.

    I hope that helps!
    Last edited by mlse; 11-15-2007 at 10:44 AM.


  •  

    Posting Permissions

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