简体   繁体   中英

Getting the URL of an iFrame cross domain and protocol in jQuery

I am basically creating an external shopping cart system for users on my site that will lead to a secure system that I am paying for, and in their shopping pages, they auto-generate a PHP GET variable called CFTOKEN that I need to access so I can send cart updates.

I am loading an iframe with the URL that redirects to the shopping cart with the CFTOKEN variable in the URL. I need to get this variable in javascript so I can send updates to the cart.

I have tried accessing the URL by the following code:

$("#iframe").contents().get(0).location.href

but I not only get a cross domain error, I get undefined for the location.

How can I get the URL?

You simply can't in modern browsers, it would've been a security issue. I'm sorry.

You can read more about it here: How do I get the current location of an iframe?

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