简体   繁体   中英

GET variables of parent window to iframe url

I'm trying to pass on the parent url variables to the variables of the iframe url.

For example if the parent url is: http://mywebsite.com/autos-zoeken?sessid=s838c7e5c3be0452fc38f4ffb6f307ed7&code=be3f&whsearch_key=6568

The iframe url needs to become: http://anotherwebsite.com/s838c7e5c3be0452fc38f4ffb6f307ed7/be3f/stock/6568/

The code I'm using now is:

<?php $val1 = $_GET[“sessid“]; $val2 = $_GET[“code“]; $val3 = $_GET[“whsearch_key“]; echo "<iframe src='http://anotherwebsite.com/' . $val1 . '/' . $val2 . '/stock/' . $val3 . '/' id='blockrandom' width='1000' height='1200' scrolling='auto' frameborder='0' class='wrapper'> Your browser doesn't support inline frames.</iframe>"; ?>

The result on the website is: http://anotherwebsite.com/' . . '/' . . '/stock/' . . '/' id='blockrandom1' etc

So the variables aren't being put in the right place in the iframe url

What am I doing wrong here?

this should work fine:

echo "<iframe src='http://anotherwebsite.com/$val1/$val2/stock/$val3/' id='blockrandom' width='1000' height='1200' scrolling='auto' frameborder='0' class='wrapper'> Your browser doesn't support inline frames.</iframe>";

the problem is with all your quote's inside your src, it thinks it needs to stop your src after http://anotherwebsite.com/ and you don't need to use "." inbetween because you used doubleqouote on start, you can just use variables inside doublequotes.

    echo "<iframe src='http://anotherwebsite.com/$val1/$val2/stock/$val3/' id='blockrandom' width='1000' height='1200' scrolling='auto' frameborder='0' class='wrapper'>Your browser doesn't support inline frames.</iframe>"; ?> 

您不需要转义变量

You're not actually concatenating multiple strings, you're just building a single string. Take a look at a simplified example:

"<iframe src='http://anotherwebsite.com/' . $val1"

That's just one string which happens to have a period between some spaces. In order to use the . concatenation operator you need to terminate the string first:

"<iframe src='http://anotherwebsite.com/'" . $val1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM