Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Dreamweaver accessing JavaScript function

Options
  • 10-05-2006 1:11pm
    #1
    Moderators, Education Moderators, Technology & Internet Moderators Posts: 35,079 Mod ✭✭✭✭


    I designing a website that I am having a bit of trouble with.

    I want to have a picture on a page (lets say page1.html) and have a link to another page (lets say page2.html).
    When I click on the link I want it to display page2.html and then run a javascript function on that page. Any ideas?

    Any help on this would be great.


Comments

  • Closed Accounts Posts: 19 TheMoralist


    Possible solution:

    When you click the link on page1, the link should read:
    <a href="page2.html?fromPage1=yes">Page 2</a>
    

    On page 2 html, call a function in the onload event of the body tag:
    <head>
    <script type="type/javascript">
    function checkIfFromPage1(){
       //parse off the querystring and then call your function if you determine its from page 1
    }
    </script>
    </head>
    <body onload="checkIfFromPage1()">
    

    That might help.


  • Moderators, Education Moderators, Technology & Internet Moderators Posts: 35,079 Mod ✭✭✭✭AlmightyCushion


    That kind of helps but it's still not what I'm looking for.
    Sorry should have said this. There could be multiple pages going to page2 e.g page1 page3 page4 but I want to pass a number to the function in page2.

    Here is my scenario.

    I have a gallery page called gallery.htm. It contains a function that holds an array of pictures. If a user clicks the next button it displays to picture2.jpg if they click it again it displays picture3.jpg.

    I want to make it so that if the user is on page1.htm and clicks a thumbnail there it will go to the gallery.htm page and display that picture just larger.

    For example if the user clicks on picture4.jpg(thumbnail size) it goes to the gallery page and displays picture4.jpg.

    So when the user clicks the thumbnail picture4.jpg it would send 4 to the function so that the gallery.htm would display the forth picture in the array in this case picture4.jpg.


  • Registered Users Posts: 683 ✭✭✭Gosh


    Hope this helps ...

    On the calling page set a URL to the page that displays the larger picture with a URL parameter of "expand=largerimagename.jpg"

    On the page that displays the larger image include the following (between <head> and </head>
    <script language=javascript>
    function getURLParameters() 
    {
    	var sURL = window.document.URL.toString();
    	if (sURL.indexOf("?") > 0){
    		var arrParams = sURL.split("?");
    		var arrURLParams = arrParams[1].split("&");
    		var arrParamNames = new Array(arrURLParams.length);
    		var arrParamValues = new Array(arrURLParams.length);
    		var fnd = 0;
    		var i = 0;
    		for (i=0;i<arrURLParams.length;i++){
    			var sParam =  arrURLParams[i].split("=");
    			arrParamNames[i] = sParam[0];
    			if (sParam[0] == "expand"){
                               document.write('<img src="' +sParam[1]+ '">');
                               fnd = 1;
                            }  	
    		}
                    if (fnd == 0){
                       document.write('expand parameter not passed');
                    }
    	}else{
    		document.write('No URL parameters passed');
    	}
    }
    </script>
    


    There are 3 outcomes when executing this script:

    1) the expand= parameter was passed (first document.write to display img)
    2) expand= parameter not passed (second document.write)
    3) no URL parameters passed (third document.write)

    For 2) and 3) you could replace these with some other action

    On the page that displays the larger image include the following where you want the larger image displayed on the page
    <script language=javascript>
    getURLParameters();
    </script>
    

    You'll have to consider <noscript></noscript> actions where Javascript is not enabled in the browser.

    Another alternative, since you're using DreamWeaver is to use the Photo Album extension which creates a photo gallery from your original pictures plus an index page of thumbnails. Click on a thumbnail and it displays the original picture and allows you to navigate through the album from that point. Check it out [URL=""]here[/URL] - there are other versions available for other versions of Dreamweaver - you'll need to search Dreamweaver Exchange.


Advertisement