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 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Can I put a javascript in a CSS?

    If I add/create a javascript in notepad and save the file as .js, will this be a real javascript file? If I pute this file on a web site, can I put a code something like this (<SCRIPT LANGUAGE="JavaScript" c="popup.js"></SCRIPT>) in the head of my web page to call the script? The sample code I put up dosen't work. Will a Javascript work in a CSS page? I have several pages that will use the same code and I would like to use an off page script.

  • #2
    New Coder
    Join Date
    Nov 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    at first i thought this was a joke, and i was going to give a funny sarcastic response, but i did a google search and i found out that it is possible, but has huge limitations, essentially its worthless for anything deep but here is a link

    http://www.quirksmode.org/css/javascript.html

  • #3
    New Coder mentalhorse's Avatar
    Join Date
    Jul 2005
    Location
    Duanesburg, NY
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If all your trying to do is have more than one page share the same javascript then just link to it.
    ex.

    <html>
    <head><title>adfapeoi</title>
    <script type="text/javascript" src="whatever.js"></script>
    </head>
    etc.

    ^^ you can put that <script> tag any number of pages and they will all execute whatever.js
    Why is a raven like a writing desk?

  • #4
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Gameport,
    Your page on browsers was very interesting. I bookmarked it so I can read it again. There's a lot there. Your research on my CSS/script is interesting. I would advise anyone here to visit your page.

    Mentalhorse,
    I will try the script you suggested. I hope it works. It will save me a lot of time.

    Thanks for the advice.

  • #5
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I can't seem to get <script type="text/java script" src="popup.js"></script> to work. Maybe my script file isn't right. The script works well on the page but it won't from an outside page. I'm using a popup script I got from this site. I copied the script into Notepad and saved it with a .js extension. I added the script file in my website with my HTM files. I called it "popup.js" and it shows as a js file icon. Part of the script gos in the head and the other part gos in the body. I put the head part of the script in the file and I put the body part of the script on the page that the script is called to.
    Last edited by metmmsc; 12-31-2005 at 03:11 AM.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    post the code for popup.js
    Note you do not put the script tags in an external js file.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I copied the script below into notepad and saved the file with a .js extension instead of the Tex extension.
    --------------------------------------------------------------

    <script type="text/javascript">

    // JK Pop up image viewer script- By JavaScriptKit.com
    // Visit JavaScript Kit (http://javascriptkit.com)
    // for free JavaScript tutorials and scripts
    // This notice must stay intact for use

    var popbackground="lightskyblue" //specify backcolor or background image for pop window
    var windowtitle="Image Window" //pop window title

    function detectexist(obj){
    return (typeof obj !="undefined")
    }

    function jkpopimage(imgpath, popwidth, popheight, textdescription){

    function getpos(){
    leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
    toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
    if (window.opera){
    leftpos-=screenLeft
    toppos-=screenTop
    }
    }

    getpos()
    var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,left='+leftpos+',top='+toppos
    var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
    if (typeof jkpopwin=="undefined" || jkpopwin.closed)
    jkpopwin=window.open("","",winattributes)
    else{
    //getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
    //jkpopwin.moveTo(leftpos, toppos)
    jkpopwin.resizeTo(popwidth, popheight+30)
    }
    jkpopwin.document.open()
    jkpopwin.document.write('<html><title>'+windowtitle+'</title><body '+bodyattribute+'><img src="'+imgpath+'" style="margin-bottom: 0.5em"><br>'+textdescription+'</body></html>')
    jkpopwin.document.close()
    jkpopwin.focus()
    }

    </script>

    ----------------------------------------------------------------

    I added the script call line in the "head"
    ------------------------------------------------------------------
    <script type="text/javascript" src="popup.js"></script>
    ---------------------------------------------------------------------


    And I added the second part of the script in the "body"
    --------------------------------------------------------------------
    - <a href="#" onClick="jkpopimage('images/rescue.jpg', 200, 300, 'rescue of a small whale'); return false">whale rescue</a><br>


    Maybe, you would like to see the test page. It's at this location:
    http://www.marinemammalstrandingcenter.org/test.htm
    The script is in this page.

  • #8
    New Coder mentalhorse's Avatar
    Join Date
    Jul 2005
    Location
    Duanesburg, NY
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Like metmmsc said. You don't put <script></script> tags in external javascript.
    Why is a raven like a writing desk?

  • #9
    New Coder mentalhorse's Avatar
    Join Date
    Jul 2005
    Location
    Duanesburg, NY
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OOPS i meant like aerospace said.. Sorry!
    Why is a raven like a writing desk?

  • #10
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts
    WOW!! I see the light. My problem was that I had <script></script> in my external js file. I took <script></script out of the js file and it works. I no longer get error messages. The computer reads the page and when it comes to <script type="text/javascript" SEC="pop up.J's"></script>, the J's file is read into the HTML file and the script's function is carried out. Adding <script></script> to both the HTML file and the js file is like a double negative. Thanks again. This is a great forum with allot of talent.


  •  

    Posting Permissions

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