0

I am using iWeb for some simple webpage development, and I have put some JavaScript in an HTML widget. The first widget I did worked perfectly, but the second one I am having issues with. The script is supposed to pull the $_GET variables from the URL to address the user. My script worked perfectly outside of iWeb, but fails what I copy it into an iWeb widget. Here is my code:

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">

//Replace all String Function
String.prototype.replaceAll = function(search, replace){
    //if replace is null, return original string otherwise it will
    //replace search string with 'undefined'.
    if(!replace) 
        return this;

    return this.replace(new RegExp('[' + search + ']', 'g'), replace);
    };

//GET from URL
var getVars = {},
    args = location.search.substr(1).split(/&/);
for (var i=0; i<args.length; ++i){
    var tmp = args[i].split(/=/);
    if(tmp[0] != ""){
        getVars[decodeURIComponent(tmp[0])] = decodeURIComponent(tmp.slice(1).join("").replaceAll("+", " "));
        }
    }

    $(document).ready(function(){
        $("#rsvpName").html(getVars["rsvpName"]);

        if( getVars["rsvpResponse"] == "1" )
            $("#rvspMessage").html( "You will be attending as part of a party of " + getVars["rsvpNum"] + "." );

        else if( getVars["rsvpResponse"] == "0" )
            $("#rvspMessage").html("We regret you will not be able to attend!");

        alert( getVars["rsvpName"] + getVars["rsvpResponse"] + getVars["rsvpNum"]);
        });
</script>

<h1>Thank you, <b><span id="rsvpName">Name</span></b>, for RSVPing.</h1>
<p id="rvspMessage">Message</p>

Anyone have a suggestion?

Andrew
  • 467
  • 3
  • 7
  • 22
  • 2
    I believe it's not working because iWeb widgets are included via iframes (not an Apple thing). That will cause `location.search.substr(1).split(/&/);` to return something different to what you can see/expect. As for a solution, I'm not sure, I stopped using iWeb because of its limitations. – Graham Walters Aug 31 '13 at 20:11
  • 1
    like @GrahamWalters said it must be because of an iframe so instead of args = location.search.substr(1).split(/&/); try using args = document.referrer.substr(1).split(/&/); and see if it works. – Kishore Aug 31 '13 at 20:19
  • I figured it was something to that effect, but I had no idea how to fix it. Thanks, works perfect! – Andrew Aug 31 '13 at 21:00

0 Answers0