Arquivo Eletrônico

2011, May-27

Pass Variables to a Widget Inside an iWeb Page

I recently created a contact form inside an iWeb page using the method I previously explained but I needed to pass some arguments to the PHP and Javascript code to the widget file containing the code. If you simply add the variables at the end of the url in the form: MyPage.html?arg1=val1&arg2=val2 simply won’t work because the variables are available within the MyPage.html domain and are not passed over to the widget0_markup.html file.

This problem can be solved with the help of some javascript code, specifically by using the property.

What does is to set or return the query string variable from the “?” question mark in the current URL. So, taking advantage of it, we are going to edit the iWeb page so that it passes the arguments contained in over to the widget0_markup.html file.

This is how I did it:

  • Pass the arguments you need in the url as follows:
  • Open ‘MyPage.html’ with your favorite html editor and find the line that has the code that loads the widget. It should look something like this:

    var widget0_htmlMarkupURL = ".//MyPage_files/widget0_markup.html";
  • Now simply add the following to the end og that line:
  • so it looks like this:

    var widget0_htmlMarkupURL = ".//MyPage_files/widget0_markup.html";

That’s it, now you can access the variables arg1 and arg2 within your widget0_markup.html file.