SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question JavaScript and query strings

    This is doing my head in!! I was using Macromedia Dreamweaver's showHideLayers function in conjunction with Flash using get URL. Here's the header JS:

    Code:
    function MM_showHideLayers() { //v3.0
      var i,p,v,obj,args=MM_showHideLayers.arguments;
      for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
        if (obj.style) { obj=obj.style; v=(v=='show')?'visible': (v='hide')?'hidden':v; }
        obj.visibility=v; }
    }
    
    function hideLayers() {
    
       MM_showHideLayers('Home','','hide')
       MM_showHideLayers('MarketAnalysis','','hide')
       MM_showHideLayers('ProductDevelopment','','hide')
       MM_showHideLayers('Engineering','','hide')
       MM_showHideLayers('PackagingDesign','','hide')
       MM_showHideLayers('LaunchPublicity','','hide')
       MM_showHideLayers('Logistics','','hide')
       MM_showHideLayers('AccountingForSuccess','','hide')
    }
    In the Flash movie the AS was something like:

    Code:
    onRelease {
    getURL ("javascript:hideLayers(); MM_showHideLayers('LayerNameToShow','','show');")
    }
    This worked fine, but when you try and do this from a frameset on one server to content on another server (crap I know, but the client is skimping on their hosting) Flash doesn't pass the JavaScript back to the page for some reason. I need to either,

    a) find a way (without playing with server settings or anything like that) to make Flash pass that JavaScript to the right page, or ...

    b) use a query string to select the layer instead (ie: the AS getURL function would simply contain 'teamwork.html?layer=LayerName').

    I'm currently favouring b) but I can't get it to work with my rudimentary JS knowledge! All I want to do is pull the value of the 'layer' field in a query string into the standard MM showHideLayers function to show the appropriate layer.

    Can anyone help or suggest a better way to do this?? Please!!

    G

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got a functon for that.
    Code:
    function parseGetVars() {
    	var getVars = new Array();
    	var qString = top.location.search.substring(1);
    	var pairs = qString.split(/\&/);
    	for (var i in pairs) {
    		var nameVal = pairs[i].split(/\=/);
    		getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
    		}	
    	return getVars;
    	}
    var g = parseGetVars();
    
    // Code for you...
    alert(g['layer']);
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice! Thanks -- I'll give it a go.

    G

  4. #4
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works beautifully like this:

    Code:
    function parseGetVars() {
    	var getVars = new Array();
    	var qString = top.location.search.substring(1);
    	var pairs = qString.split(/\&/);
    	for (var i in pairs) {
    		var nameVal = pairs[i].split(/\=/);
    		getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
    		}	
    	return getVars;
    	}
    
    var layer = parseGetVars();
    
    if (layer['layer'] == undefined) {
    var layerName = 'Home';
    }
    else
    {
    var layerName = layer['layer'];
    }
    Thanks!

    Just had a brain-wave though. I'm working this problem the wrong way around. What will be far easier (and I'm going to do this in a minute) will be to control the Flash movie from the page using JavaScript rather than trying to make a Flash movie control the page. I'll have a play around, but I suspect that ditching the buttons in the Flash movie (which are duplicate and unnecessary content anyway -- designers!) and using the existing HTML buttons with JS attached to control the play head of the animation will be much better.

    I'll let you know what I settle on!

    G

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool. Let me know. Also, here's a little schooling on the ternary syntax....
    Code:
    // You can replace this
    if (layer['layer'] == undefined) {
    var layerName = 'Home';
    }
    else
    {
    var layerName = layer['layer'];
    }
    
    // With this
    var layerName = (layer['layer'] == undefined) ? 'Home' : layer['layer'];
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the tip. I'm just learning JS really but it'll come. I know VBS pretty well (I code in VBS for ASP) but the syntax of JS leaves me scratching my head sometimes!

    I'll post my finished result.

    G


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
  •