Forum Moderators: open

Message Too Old, No Replies

How to make an iframe inherit url attributes

How can I make an iframe get url attributes?

         

w3bm1str3ss

5:46 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Ok so I am trying to make an iframe take attributes from teh url, like:

http:test.html?you=1&me=2

I got a piece of code that gets the parameters but I don't know how to get it into the iframe.

Attempted use in putting it in the iframe:


<IFRAME id="isFrameSeven" name="isFrameSevenx" src="http://test.html?javascript=getURLParameters()"></IFRAME>

URL Getter Code:


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 i = 0;
for (i=0;i<arrURLParams.length;i++)
{
var sParam = arrURLParams[i].split("=");
arrParamNames[i] = sParam[0];
if (sParam[1]!= "")
arrParamValues[i] = unescape(sParam[1]);
else
arrParamValues[i] = "No Value";
}
for (i=0;i<arrURLParams.length;i++)
{
alert(arrParamNames[i]+" = "+ arrParamValues[i]);
}
}
else
{
alert("No parameters.");
}
}

orion_rus

7:49 am on Jun 7, 2005 (gmt 0)

10+ Year Member



i think it would be better done on a server side
but you can make this:
<script>
newstr=substr(location.href,20,20); // 20 should be changed to a real position parameters in a string;
//newstr now look like this:?you=1&me=2
document.getElementById('isFrameSeven').src='http://test.html'+newstr;
</script>
i hope i was clear. Good luck to you

kaled

9:04 am on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For maximum speed, use document.write() to create the IFrame.

It would go something like this

<script>
<!--
document.open();
document.write('<iframe src="' + getUrl() + '">');
document.writeln('<\/iframe>')
-->
</script>

<noscript>
<iframe src="url"></iframe>
</noscript>

NOTES
1) When embedded in a page, scripts should be enclosed within html comments as shown above.
2) When placed in a string, the / character should be escaped using the \ character. This is not strictly necessary (I think) when the script is external to the page but is harmless.
3) In order to allow your page to work without javascript, you should include a <noscript> version as above.
4) DON'T get clever and try to use a single </iframe> to close both versions. This may work on some browsers but will break on others and your code will not validate.

Kaled.

w3bm1str3ss

2:26 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



<DIV id="frameSeven">
<IFRAME id="isFrameSeven" name="isFrameSevenx" src="javascript:window.location='http://netrecon/cgi-bin/applicationData.pl?'+parent.delineate2(document.HiddenURL.parameters.value)" frameBorder=0 marginwidth="0" marginheight="0" vspace="0" hspace="0" style="overflow:visible; width:100%; height:82%; display:block"></IFRAME>
</DIV>

this is what I am trying that is not working now!

w3bm1str3ss

2:29 pm on Jun 7, 2005 (gmt 0)

10+ Year Member




<FORM NAME="HiddenURL">
<INPUT TYPE="hidden" NAME="parameters" SIZE="35">
</FORM>
<SCRIPT LANGUAGE="javascript">
var locate = window.location
document.HiddenURL.parameters.value = locate
var text = document.HiddenURL.parameters.value
function delineate2(str){
point = str.lastIndexOf("?");
return(str.substring(point+1,str.length));
}
document.write("?" +delineate2(text));
</SCRIPT>

here is the script it is calling, the iframe url seems unable to be changed with javascript! Can anyone help on this one? I have to do it in the iframe src, there are tabs calling this hidden div into play when you click the links above and it stops working if i put the script in that ahref