0

I'm trying to combine some dynamic parameters that are sent through the URL into a frame, but nothing works. Tried them inside the tags, outside, before, after... Can somebody shed a light on this?

URL on the top frame is http://www.someurl.com/someparameters.html?country=EN_US. The first script will get the language (EN) and market (US). Then, the frameset is built with another page and our target page, which should be called with the link "http://www.someurl.com/somefolders?LANGUAGE=EN&MARKET=US&somefixedparameters=123"

This is the source code of the frameset that isn't working.

<!DOCTYPE html>
<html>
<script type="text/javascript"><!--
var url = window.location.href;
var language = url.substr(url.indexOf("country=") + 8,2);
var market = url.substr(url.indexOf("country=") + 11,2);
}
</script>
<frameset rows="36px,*" frameborder="0">
<frame id="main" src="header_cgh.html?country=BR_OP" noresize="noresize" scrolling="no" border="1" bordercolor=white>
<frame id="flow" src="">
</frameset>
<script type="text/javascript"><!--
document.getElementById("flow").src = "http://www.someurl.com/somefolders?LANGUAGE=" + language + "&MARKET=" + market + "&somefixedparameters=123";
</script>
</html>

Thanks for your help!

UPDATE: After opening Chrome's Javascript console and inserting the command:

document.getElementById("flow").src = "http://www.someurl.com/somefolders?LANGUAGE=" + language + "&MARKET=" + market + "&somefixedparameters=123"

It returned the expected result. But it won't happen on its own.

2
  • Try sharing a jsfiddle. Commented Dec 3, 2014 at 19:37
  • The weird thing is, the frameset is loaded, the first frame loads. When I open Chrome and use the console copying and pasting the same entry ||document.getElementById("flow").src = "someurl.com/somefolders?LANGUAGE=" + language + "&MARKET=" + market + "&somefixedparameters=123";|| it loads correctly. So, what I think is that it's missing a "trigger" somewhere. Commented Dec 3, 2014 at 19:56

2 Answers 2

1

Change your script to this:

window.onload = function() {
    var url = window.location.href;
    var language = url.substr(url.indexOf("country=") + 8,2);
    var market = url.substr(url.indexOf("country=") + 11,2);
    document.getElementById("flow").src = "/somefolders?language=" + language + "&market=" + market;
}

And put it in a script tag in your head.

Also, as a heads up: if someone requests the main frameset page without a query string, or without the country parameter in there, then indexOf returns -1, and you end up with nonsense in your language and market variables. You'll want to come up with a more robust way of getting that information.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the heads-up as well. I'll try a workaround for that. Anyway, since the page is running in a kiosk and the initial request will be always done through the shortcut/links created for that environment I just have to make sure they always have this information.
0

Here is an example using postMessage. See if this handles what you're looking for:

<iframe src="http://a.JavaScript.info/files/tutorial/window/receive.html" id="iframe" style="height:60px"></iframe>

<form name="form">
  <input type="text" name="msg" value="Your message"/>
  <input type="submit"/>
</form>

<script>

  var win = document.getElementById("iframe").contentWindow

  document.forms.form.onsubmit = function() {
    win.postMessage(
      this.elements.msg.value,
      "http://a.JavaScript.info" 
    )
    return false
  }

</script>

From http://javascript.info/tutorial/cross-window-messaging-with-postmessage

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.